# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226994 | Charis02 | 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 "grader.h"
#define N 1505
int par[N],edges[N];
int f(int x)
{
if(par[x]==x)
return x;
return par[x]=f(par[x]);
}
bool issameset(int x,int y)
{
int fx=f(x);
int fy = f(y);
return (fx==fy);
}
void join(int x,int y)
{
if(issameset(x,y))
return;
int fx = f(x);
int fy = f(y);
par[fx] = fy;
edges[fy]+=edges[fx];
return;
}
void initialize(int n)
{
for(int i = 0;i < n;i++)
{
edges[i]=n-1;
par[i]=i;
}
return;
}
int hasEdge(int u, int v)
{
int fu = f(u);
int fv = f(v);
edges[fu]--;
edges[fv]--;
if(edges[fu] == 0 || edges[fv] == 0)
{
join(u,v);
return 1;
}
else
return 0;
}