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;
const int maxn = 1510 + 10;
int rnk[maxn];
int link[maxn];
int cnt[maxn][maxn];
int n;
int get(int x) {
if (x == link[x]) {
return x;
}
return link[x] = get(link[x]);
}
void initialize(int n) {
::n = n;
for (int i = 1; i <= n; ++i) {
link[i] = i;
rnk[i] = 1;
}
}
int hasEdge(int u, int v) {
u += 1; v += 1;
u = get(u); v = get(v);
if (u == v) return 1;
cnt[u][v] +=1;
cnt[v][u] += 1;
if (cnt[u][v] < rnk[u] * rnk[v]) return 0;
if (rnk[u] < rnk[v]) swap(u, v);
rnk[u] += rnk[v];
link[v] = u;
for (int i = 1; i <= n; ++i) {
cnt[i][u] += cnt[i][v];
cnt[u][i] += cnt[v][i];
}
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |