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;
int n;
int p[1500];
int con[1500][1500];
int find(int a) {
return p[a]<0?a:p[a]=find(p[a]);
}
void merge(int a,int b) {
a=find(a);
b=find(b);
if (a==b) {
return;
}
p[a]+=p[b];
p[b]=a;
}
void initialize(int nn) {
n=nn;
memset(p,-1,sizeof(p));
}
int hasEdge(int u,int v) {
con[find(u)][find(v)]++;
con[find(v)][find(u)]++;
if (con[find(u)][find(v)]<p[find(u)]*p[find(v)]) {
return false;
}
for(int i=0;i<n;i++) {
con[find(i)][find(u)]+=con[find(i)][find(v)];
con[find(u)][find(i)]+=con[find(v)][find(i)];
con[find(i)][find(v)]=0;
con[find(v)][find(i)]=0;
}
merge(u,v);
return true;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |