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;
struct dsu {
vector<int> p, size;
void init(int n) {
p.resize(n);
size.assign(n, 1);
for (int i = 0; i < n; i++) p[i] = i;
}
int get(int a) {
return p[a] = p[a] == a ? a : get(p[a]);
}
void add(int a, int b) {
a = get(a), b = get(b);
if (a == b) return;
if (size[a] > size[b]) swap(a, b);
size[b] += size[a];
p[a] = b;
}
};
int n;
vector connected(1500, vector(1500, true));
dsu ds;
void initialize(int _n) {
n = _n;
}
int hasEdge(int u, int v) {
ds.init(n);
connected[u][v] = connected[v][u] = false;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (connected[i][j]) ds.add(i, j);
}
}
bool ok = true;
for (int i = 1; i < n; i++) ok &= ds.get(0) == ds.get(i);
if (!ok) connected[u][v] = connected[v][u] = true;
return !ok;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |