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"
const int MAXN = 1500;
int par[MAXN];
int rk[MAXN];
int cnt[MAXN][MAXN];
int N;
int find(int x) {
if (par[x] == x) {
return x;
}
return (par[x] = find(par[x]));
}
void merge(int x, int y) {
int px = find(x);
int py = find(y);
if (px != py) {
par[px] = py;
rk[py] += rk[px];
}
}
void initialize(int n) {
N = n;
for (int i = 0; i < n; i++) {
par[i] = i;
rk[i] = 1;
}
}
int hasEdge(int u, int v) {
int px = find(u);
int py = find(v);
if (cnt[px][py] == rk[px]*rk[py]-1) {
for (int i = 0; i < N; i++) {
cnt[i][py] += cnt[i][px];
cnt[py][i] += cnt[px][i];
}
merge(px, py);
return 1;
}
else {
cnt[px][py]++;
cnt[py][px]++;
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... |