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;
int par[1505],o1,akar,n;
bool udah[1505][1505],first;
int root(int a){
if(par[a]==a)return a;
return par[a] = root(par[a]);
}
void merge(int a, int b){
par[root(b)] = root(a);
}
void initialize(int k) {
n =k ;
for(int i =0;i<n;i++){
par[i]=i;
}
first =1;
}
int hasEdge(int u, int v) {
if(first){
first = 0;
merge(u,v);
akar = u;
udah[u][v] =1;
udah[v][u] = 1;
return 1;
}
o1=0;
if(root(akar)==root(u)){
for(int i =0;i<n;i++){
if(i!=v){
if(!udah[i][v]&&root(i)==root(akar)){
o1++;
}
}
}
udah[u][v]=1;
udah[v][u]=1;
if(o1==1){
merge(u,v);
return 1;
}
return 0;
}
o1=0;
if(root(akar)==root(v)){
for(int i =0;i<n;i++){
if(i!=u){
if(!udah[i][u]&&root(i)==root(akar)){
o1++;
}
}
}
udah[u][v]=1;
udah[v][u]=1;
if(o1==1){
merge(u,v);
return 1;
}
return 0;
}
udah[u][v]=1;
udah[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... |