# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879794 | Muaath_5 | Game (IOI14_game) | C++17 | 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 <bits/stdc++.h>
using namespace std;
void initialize(int n);
int hasEdge(int u, int v);
int n;
map<pair<int, int>, int> mp;
int par[N];
int root(int x) {
return x == par[x] ? x : par[x] = root(par[x]);
}
void merge(int u, int v) {
u = root(u), v = root(v);
if (u == v) return;
par[v] = u;
}
void initialize(int cnt)
{
n = cnt;
mp.clear();
for (int i = 1; i <= cnt; i++)
par[i] = i;
}
int hasEdge(int u, int v)
{
if (u > v) swap(u, v);
if (root(u) == root(v))
return 1;
mp[{u, v}]++;
if (mp[{u, v}] == n-1) {
merge(u, v);
return 1;
}
return 0;
}