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;
set<int> s[MAXN];
int n,U,V,pai[MAXN],prof[MAXN],marc[MAXN][MAXN];
void initialize(int n)
{
for(int i=1;i<=n;i++)
{
pai[i]=i;
marc[i][i]=1;
for(int j=i+1;j<=n;j++)
s[i].insert(j), s[j].insert(i);
}
}
void see()
{
for(int i=1;i<=n;i++)
{
set<int> :: iterator it;
printf("U = %d : \n",i);
for(it=s[i].begin();it!=s[i].end();it++)
printf("%d ",*it);
printf("\n\n");
}
}
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;
set<int> :: iterator it;
if(prof[a]>prof[b])
{
marc[a][b]=1;
for(it=s[b].begin();it!=s[b].end();it++)
if(marc[a][*it]!=1)
s[a].insert(*it);
pai[b]=a;
return;
}
marc[b][a]=1;
for(it=s[a].begin();it!=s[a].end();it++)
if(marc[b][*it]!=1)
s[b].insert(*it);
pai[a]=b;
if(prof[a]==prof[b]) prof[b]++;
}
int hasEdge(int u,int v)
{
for(int i=1;i<=n;i++)
{
if(s[fd(u)].find(i)!=s[fd(u)].end() && s[fd(v)].find(i)!=s[fd(v)].end())
{
// printf("pai[%d] = %d pai[%d] = %d\n",u,fd(u),v,fd(v));
// see();
s[fd(u)].erase(v), s[fd(v)].erase(u);
return 0;
}
}
// see();
join(u,v);
return 1;
}
/*
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",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... |