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);
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;
}
cnt[v][u]++;
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... |