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"
#define NN 1500
int n, ds[NN], cross[NN][NN];
int find(int i) {
if (ds[i] < 0)
return i;
int p = find(ds[i]);
for (int j = 0; j < n; ++j)
cross[p][j] += cross[i][j], cross[j][p] += cross[i][j];
return ds[i] = p;
}
int unite(int i, int j) {
i = find(i), j = find(j);
if (i == j)
return 0;
ds[i] += ds[j];
ds[j] = i;
return 1;
}
void initialize(int n0) {
n = n0;
for (int i = 0; i < n; ++i)
ds[i] = -1;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cross[i][j] = cross[j][i] = 1;
}
int hasEdge(int u, int v) {
if (find(u) == find(v))
return 1;
u = find(u), v = find(v);
--cross[u][v];
--cross[v][u];
if (0 == cross[u][v]) {
unite(u, v);
return 1;
}
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... |