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"
#include <bits/stdc++.h>
using namespace std;
int const N = 1510;
int n, par[N], sz[N], cnt[N][N];
int find(int u) {
return par[u] == -1 ? u : par[u] = find(par[u]);
}
int merge(int u, int v) {
u = find(u), v = find(v);
assert(u != v);
if (sz[v] > sz[u])
swap(u, v);
if (++cnt[u][v] == sz[u] * sz[v]) {
par[v] = u;
sz[u] += sz[v];
for (int w = 0; w < n; w++)
cnt[u][w] += cnt[v][w], cnt[w][u] += cnt[w][v];
return true;
}
return false;
}
void initialize(int _n) {
n = _n;
fill(par, par + n, -1);
fill(sz, sz + n, 1);
}
int hasEdge(int u, int v) {
return merge(u, v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |