# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944506 | 4QT0R | Game (IOI14_game) | C++17 | 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;
int lider[1503];
int siz[1503];
int zap[1503][1503];
void initialize(int rozmiar){
n=rozmiar;
for (int i = 0; i<n; i++){
lider[i]=i;
siz[i]=1;
}
}
int Find(int v){
if (lider[v]==v)return v;
lider[v]=Find(lider[v]);
return lider[v];
}
void Union(int a, int b){
a=Find(a);
b=Find(b);
if (a==b)return;
if (siz[a]<siz[b])swap(a,b);
lider[b]=a;
siz[a]+=siz[b];
for (int i = 0; i<n; i++){
if (i==a)continue;
zap[a][i]+=zap[b][i];
zap[i][a]+=zap[i][b];
}
}
int hasEdge(int u, int v){
u=Find(u);
v=Find(v);
if (u==v)return 0;
zap[v][u]++;
zap[u][v]++;
else if (siz[v]*siz[u]>zap[v][u])return 0;
else{
Union(u,v);
return 1;
}
}