# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72592 | vex | 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>
#define n 1505
using namespace std;
int n;
int sz[maxn],p[maxn];
int uk=0;
void initialize(int N)
{
n=N;
for(int i=0;i<n;i++)
{
sz[i]=1;
p[i]=i;
}
}
int fnd(int x)
{
if(x==p[x])return x;
p[x]=fnd(p[x]);
return p[x];
}
bool same(int x,int y)
{
return fnd(x)==fnd(y);
}
void unite(int x,int y)
{
x=fnd(x);
y=fnd(y);
if(sz[x]<sz[y])swap(x,y);
sz[x]+=sz[y];
p[y]=x;
}
int hasEdge(int u,int v)
{
if(same(u,v))return 0;
u=fnd(u);
v=fnd(v);
if(sz[u]+sz[v]<n)
{
unite(u,v);
return 1;
}
return 0;
}