# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
520110 | tjd229 | Game (IOI14_game) | C++14 | 408 ms | 25104 KiB |
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"
int n;
int p[1500];
int mat[1500][1500];
int sz[1500];
int find(int a) {
if (p[a] != a) p[a] = find(p[a]);
return p[a];
}
bool dsu(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return false;
sz[a] += sz[b];
for (int i = 0; i < n; ++i) {
int par = find(i);
mat[i][a] += mat[i][b];
mat[a][i] += mat[b][i];
}
p[b] = a;
return true;
}
void initialize(int n) {
::n = n;
for (int i = 0; i < n; ++i) {
sz[i] = 1; p[i] = i;
}
}
int hasEdge(int u, int v) {
int U = find(u), V = find(v);
if (U == V) return 0;
++mat[U][V]; ++mat[V][U];
if (sz[U] * sz[V] == mat[U][V]) {
dsu(U, V);
return 1;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |