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"
#include<iostream>
using namespace std;
int s[1600],p[1600],n,g[1600][1600];
void setcreate(int a)
{
s[a]=1;
p[a]=a;
}
int setparent(int a)
{
if(a==p[a])
return a;
p[a]=setparent(p[a]);
return p[a];
}
void setunion(int a,int b)
{
a=setparent(a);
b=setparent(b);
if(a==b)
return;
if(s[a]>=s[b])
{
s[a]+=s[b];
p[b]=a;
for(int i=0;i<n;i++)
{
g[a][i]+=g[b][i];
g[i][a]=g[a][i];
}
}
else
{
s[b]+=s[a];
p[a]=b;
for(int i=0;i<n;i++)
{
g[b][i]+=g[a][i];
g[i][b]=g[b][i];
}
}
}
void initialize(int N) {
n=N;
for(int i=0;i<n;i++)
setcreate(i);
}
int hasEdge(int u, int v) {
int a=setparent(u);
int b=setparent(v);
if(g[a][b]+1==s[b]*s[a])
{
setunion(a,b);
return 1;
}
else
{
g[a][b]++;
g[b][a]++;
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... |