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>
#define fi first
#define se second
using namespace std;
int n;
vector<int> parent;
vector<int> size, cnt;
int ufind(int u) {
if (parent[u] == u) return u;
return parent[u] = ufind(parent[u]);
}
void ujoin(int u, int v) {
u = ufind(u);
v = ufind(v);
parent[v] = u;
size[u] += size[v];
cnt[u] += cnt[v];
}
void initialize(int N) {
n = N;
cnt = vector<int>(n, 0);
size = vector<int>(n, 1);
parent = vector<int>(n);
for (int i = 0; i < n; ++i) parent[i] = i;
}
int hasEdge(int u, int v) {
int a = ufind(u), b = ufind(v);
++cnt[a]; ++cnt[b];
if (a != b) {
if (cnt[a] == size[a]*(n-1) || cnt[b] == size[b]*(n-1)) 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... |