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"
#define N 1505
int par[N],edges[N][N],nn;
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)
{
int fx = f(x);
int fy = f(y);
par[fx] = fy;
for(int i = 0;i < nn;i++)
{
edges[fy][i] += edges[fx][i];
edges[fx][i] = 0;
}
for(int i = 0;i < nn;i++)
{
edges[i][fy] += edges[i][fx];
edges[i][fx] = 0;
}
return;
}
void initialize(int n)
{
nn = n;
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
if(i==j)
continue;
edges[i][j]=1;
}
par[i]=i;
}
return;
}
int hasEdge(int u, int v)
{
if(issameset(u,v))
return 0;
int fu = f(u);
int fv = f(v);
edges[fu][fv]--;
edges[fv][fu]--;
if(edges[fu][fv] == 0)
{
join(fu,fv);
return 1;
}
else
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |