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"
#define MAXN 1507
using namespace std;
int edge[MAXN][MAXN],n;
unordered_set<int> tree[MAXN];
vector<int> a,b,w;
void comp(int x,int p){
w.push_back(x);
for(int i:tree[x]){
if(i==p)continue;
comp(i,x);
}
}
void initialize(int N) {
n=N;
for(int i=1;i<=n;i++)tree[i].clear();
for(int i=1;i<=n;i++){
for(int f=1;f<=n;f++){
edge[i][f]=0;
}
}
for(int i=2;i<=n;i++){
int s=rand()%(i-1)+1;
tree[i].insert(s);
tree[s].insert(i);
}
}
int hasEdge(int u, int v){
u++; v++;
if(tree[u].find(v)==tree[u].end()){
edge[u][v]=edge[v][u]=1;
return 0;
}
w.clear();
comp(u,v); a=w;
w.clear();
comp(v,u); b=w;
for(int i:a){
for(int f:b){
if(edge[i][f]!=0)continue;
if(i==u and f==v)continue;
tree[u].erase(v);
tree[v].erase(u);
tree[i].insert(f);
tree[f].insert(i);
edge[u][v]=edge[v][u]=1;
return 0;
}
}
edge[u][v]=edge[v][u]=2;
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |