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 "bits/stdc++.h"
#include "game.h"
using namespace std;
const int sz = 1550;
int as[sz][sz];
int N;
struct DSU {
vector<int> par;
DSU(int n) {
par.assign(n, -1);
}
int Find(int v) {
if (0 > par[v]) return v;
return par[v] = Find(par[v]);
}
void Unite(int v, int u) {
v = Find(v);
u = Find(u);
if (par[v] > par[u]) {
swap(v, u);
}
par[v] += par[u];
for (int i = 0; i < N; i ++) {
as[v][i] += as[u][i];
as[i][v] += as[i][u];
}
par[u] = v;
}
};
DSU* dsu;
void initialize(int n) {
N = n;
dsu = new DSU(n);
}
int hasEdge(int u, int v) {
u = dsu->Find(u);
v = dsu->Find(v);
int n = -dsu->par[u];
int m = -dsu->par[v];
if (n < m) {
swap(u, v);
}
if (as[u][v] == n * m - 1) {
as[u][v] ++;
as[v][u] = as[u][v];
dsu->Unite(u, v);
return 1;
} else {
as[u][v] ++;
as[v][u] = as[u][v];
}
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... |