This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#include "game.h"
#endif
#include "bits/stdc++.h"
using namespace std;
const int maxn = 1505;
int avail[maxn][maxn];
int par[maxn];
int N;
int find(int u) {
return (par[u] < 0 ? u : par[u] = find(par[u]));
}
void initialize(int n) {
N=n;
for (int i=0; i<n; ++i) par[i] = -1;
for (int i=0;i<n;++i) {
for(int j=0;j<n;++j)
avail[i][j]=1;
}
}
int hasEdge(int u, int v) {
u = find(u); v = find(v);
assert(find(u) != find(v));
if (avail[u][v] == 1) {
par[v]=u;
for(int i=0;i<N;++i){
if(par[i]<0 and u != i) {
avail[u][i]=avail[i][u]=avail[u][i]+avail[v][i];
}
}
return 1;
} else {
avail[u][v]--;
avail[v][u]--;
return 0;
}
}
#ifdef LOCAL
int read_int() {
int x;
cin >> x;
return x;
}
int main() {
int n, u, v;
n = read_int();
initialize(n);
for (int i = 0; i < n * (n - 1) / 2; i++) {
u = read_int();
v = read_int();
printf("%d\n", hasEdge(u, v));
}
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |