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 UFDS {
int n, cc;
vector<int> len, par;
void init(int x) {
n = cc = x;
par.resize(n+2);
len.assign(n+2, 1);
iota(par.begin(), par.end(), 0);
}
int fin(int v) { return par[v] == v ? v : par[v] = fin(par[v]); }
bool join(int a, int b) {
a = fin(a); b = fin(b);
if(a == b) return false;
if(len[a] < len[b])
swap(a, b);
par[b] = a;
len[a]+=len[b];
cc--;
return true;
}
};
int n; bool adj[1505][1501];
void initialize(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) adj[i][j] = adj[j][i] = 1;
}
}
int hasEdge(int u, int v) {
if (u < v) swap(u, v);
UFDS ufds; ufds.init(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) if (!(i == u && j == v) && adj[i][j]) {
ufds.join(i, j);
}
}
if (ufds.cc == 1) {
adj[u][v] = adj[v][u] = 0;
return 0;
} else {
return 1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |