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;
typedef long long ll;
const int N=1500;
int n;
int p[N];
int sz[N];
int c[N][N];
void initialize(int _n)
{
n=_n;
for(int i=0;i<n;i++)
{
p[i]=i;
sz[i]=1;
}
}
int find_set(int a)
{
if(a==p[a]) return a;
else return p[a]=find_set(p[a]);
}
int merge_sets(int a,int b)
{
a=find_set(a);
b=find_set(b);
c[a][b]++; c[b][a]++;
if(c[a][b]==sz[a]*sz[b])
{
if(sz[a]<sz[b]) swap(a,b);
p[b]=a;
sz[a]+=sz[b];
for(int i=0;i<n;i++)
{
if(i==a||i==b) continue;
c[a][i]+=c[b][i];
c[i][a]+=c[i][b];
}
return 1;
}
return 0;
}
int hasEdge(int u, int v)
{
return merge_sets(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... |