# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659050 | Danilo21 | 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 "game.h"
#include <vector>
const mxN = 1510;
int N, f[mxN], cnt[mxN][mxN];
int Find(int s){
if (f[s] == s) return s;
return f[s] = Find(f[s]);
}
bool Union(int u, int v){
u = Find(u); v = Find(v);
cnt[u][v]--;
cnt[v][u]--;
if (!cnt[u][v]){
for (int i = 0; i < N; i++){
cnt[u][i] += cnt[v][i];
cnt[i][u] += cnt[i][v];
}
f[v] = u;
return 1;
}
return 0;
}
void initialize(int n){
N = n;
for (int i = 0; i < N; i++){
f[i] = i;
for (int j = 0; j < N; j++)
if (i^j) cnt[i][j] = 1;
}
}
int hasEdge(int u, int v){ return Union(u, v); }