# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
162641 | demetre | Game (IOI14_game) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
int n, a, b, f[10001][10001], fix[10001], p[10001];
int getcol (int l){
if (l == p[l])
return l;
return getcol (p[l]);
}
void col (int k, int l){
int w = getcol(k);
int u = getcol(l);
p[w] = u;
fix[u]+=fix[w];
fix[w] = 0;
p[k] = l;
for (int i = 0; i < n; i++){
f[u][i]+=f[w][i];
f[i][u]+=f[i][w];
}
}
int main (){
cin >> n;
for (int i=0; i<n; i++){
p[i] = i;
fix[i] = 1;
}
for (int i=1; i<=n*(n-1)/2; i++){
cin >> a >> b;
a = getcol(a);
b = getcol(b);
f[a][b]++;
f[b][a]++;
if (f[a][b] == fix[a]*fix[b]){
cout << "YES" << endl;
if (fix[a] >= fix[b])
swap(a, b);
col (a, b);
}
else
cout << "NO" << endl;
}
}