# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132622 | junodeveloper | 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"
int par[1500], rk[1500];
int cnt[1500][1500], sz[1500];
int pn(int u){return u==par[u]?u:pn(par[u]); }
void us(int a, int b) {
a=pn(a), b=pn(b);
if(rk[a]<rk[b]) swap(a,b);
par[b]=a;
sz[a]+=sz[b];
if(rk[a]==rk[b])rk[a]++;
}
void initialize(int n) {
int i, j;
for(i=0; i<n; i++) {
for(j=0; j<n; j++) cnt[i][j] = 0;
par[i] = i;
sz[i] = 1;
}
}
int hasEdge(int u, int v) {
u=pn(u),v=pn(v);
if(u==v) return 1;
else if(u>v) swap(u,v);
cnt[u][v]++;
if(cnt[u][v]==sz[u]*sz[v]) {
us(u,v);
return 1;
}
return 0;
}