#include <bits/stdc++.h>
using namespace std;
struct dsu {
int n;
vector<int> p, c, f;
dsu() {}
dsu(int m) {
n = m;
p.assign(n, 0);
c.assign(n, 1);
f.assign(n, 0);
iota(p.begin(), p.end(), 0);
}
int find(int x) {
if (x == p[x]) return x;
return p[x] = find(p[x]);
}
void merge(int a, int b) {
p[b] = a;
f[a] = f[a] + f[b] - c[a] * c[b] * 2;
c[a] += c[b];
}
};
int n;
dsu d;
void initialize(int N) { n = N, d = dsu(n); }
int hasEdge(int u, int v) {
u = d.find(u);
v = d.find(v);
if (u == v) return 0;
d.f[u]++;
d.f[v]++;
if (d.f[u] == d.c[u] * (n - d.c[u]) || d.f[v] == d.c[v] * (n - d.c[u])) {
d.merge(u, v);
return 1;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |