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<bits/stdc++.h>
using namespace std;
const int MAXN=1502;
int cnte[MAXN][MAXN];
int par[MAXN],n1;
int asked[MAXN][MAXN];
void join(int p,int q)
{
for(int i=0;i<n1;i++)
{
if(par[i]==q)par[i]=p;
}
for(int i=0;i<n1;i++)
{
if(p==i)continue;
cnte[i][p]+=cnte[i][q];
cnte[p][i]=cnte[i][p];
}
}
void initialize(int n) {
n1=n;
for(int i=0;i<n;i++)
{
par[i]=i;
for(int j=0;j<n;j++)
{
if(i!=j)cnte[i][j]=1;
}
}
}
int hasEdge(int u, int v) {
/*for(int i=1;i<=n1;i++)
{
for(int j=1;j<=n1;j++)
{
cout<<cnte[i][j]<<" ";
}
cout<<endl;
}*/
if(asked[u][v]!=0)
{
return (asked[u][v]+1)/2;
}
int p=par[u],q=par[v];
if(p==q)
{
asked[u][v]=1;
asked[v][u]=1;
return 1;
}
if(cnte[p][q]==1)
{
asked[u][v]=1;
asked[v][u]=1;
join(p,q);
return 1;
}
else
{
cnte[q][p]--;
cnte[p][q]--;
asked[u][v]=-1;
asked[v][u]=-1;
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... |