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>
#include "game.h"
using namespace std;
const int MAXN=1510;
int n,N,U,V,pai[MAXN],prof[MAXN],q[MAXN][MAXN];
void initialize(int n)
{
N=n;
for(int i=0;i<n;i++)
{
pai[i]=i;
for(int j=0;j<n;j++)
q[i][j]=1;
}
}
int fd(int v)
{
if(v==pai[v]) return v;
return pai[v]=fd(pai[v]);
}
void join(int a,int b)
{
a=fd(a); b=fd(b);
if(a==b) return;
if(prof[a]>prof[b]) swap(a,b);
for(int i=0;i<N;i++)
q[b][i]+=q[a][i], q[i][b]+=q[i][a];
pai[a]=b;
if(prof[a]==prof[b]) prof[b]++;
}
int hasEdge(int u,int v)
{
int U=fd(u), V=fd(v);
if(q[U][V]==1)
{
// printf("pai[%d] = %d pai[%d] = %d\n",u,U,v,V);
// printf("q = %d q = %d\n",q[U][V],q[V][U]);
join(u,v);
return 1;
}
q[U][V]--; q[V][U]--;
// printf("q = %d q = %d\n",q[U][V],q[V][U]);
return 0;
}
/*
int main ()
{
scanf("%d",&n);
initialize(n);
for(int i=0;i<n*(n-1)/2;i++)
{
scanf("%d %d",&U,&V);
printf("%d\n\n",hasEdge(U,V));
}
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |