Code Monkey home page Code Monkey logo

contests's Introduction

contests's People

Contributors

johniel avatar

Watchers

 avatar  avatar

contests's Issues

CF446div2E

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

class PersistentUnionFind {
public:
  PersistentUnionFind(int n)
  {
    rank.resize(n, 0);
    for (int i = 0; i < n; ++i) {
      parent.push_back(make_pair(i, -1));
    }
  }
  int find(int n)
  {
    return find(n, cnt);
  }
  int find(int n, int t)
  {
    if (parent[n].second <= t) {
      return n;
    } else {
      return find(parent[n].first, t);
    }
  }
  void unite(int a, int b)
  {
    a = find(a, cnt);
    b = find(b, cnt);
    if (rank[a] > rank[b]) {
      parent[b] = make_pair(a, cnt);
    } else {
      parent[a] = make_pair(b, cnt);
      if (rank[a] == rank[b]) rank[b]++;
    }
    ++cnt;
  }
  bool isSameSet(int a, int b)
  {
      return isSameSet(a, b, cnt);
  }
  bool isSameSet(int a, int b, int t)
  {
      return find(a, t) == find(b, t);
  }
private:
  vector<int> rank;
  vector<pair<int, int>> parent;
  int cnt = 0;
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    PersistentUnionFind uf(n);
    for (int i = 0; i < m; ++i) {
      int a, b, cost;
      cin >> a >> b >> cost;
    }
    int q;
    cin >> q;
    while (q--) {
        
    }
  }
  
  return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.