# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
851801 | ntkphong | Game (IOI14_game) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
vector<vector<int>> cnt;
int nn;
int get_root(int u) {
return u = par[u] ? u : par[u] = get_root(par[u]);
}
void initialize(int n) {
par.resize(n);
for(int i = 0; i < n; i ++) par[i] = i;
cnt.resize(n, vector<int> (n, 1));
nn = n;
}
int hasEdge(int u, int v) {
u = par[u];
v = par[v];
if(u != v) {
if(u > v) swap(u, v);
cnt[u][v] -- ;
if(!cnt[u][v]) {
for(int i = v + 1; i < n; i ++) cnt[u][i] += cnt[v][i];
par[v] = u;
return 1;
}
}
return 0;
}