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[1500],sz[1500],say[1500][1500];
vector<int> ed[1500];
int find(int node){
if (par[node]==node) return node;
return par[node]=find(par[node]);
}
void initialize(int n) {
iota(par,par+n,0);
fill(sz,sz+n,1);
memset(say,0,sizeof(say));
}
int hasEdge(int u, int v) {
if (find(u)==find(v)) return 0;
u=find(u);
v=find(v);
if (say[u][v]!=sz[u]*sz[v]-1 && say[v][u]!=sz[u]*sz[v]-1){
say[u][v]++,say[v][u]++;
ed[u].push_back(v);
ed[v].push_back(u);
return 0;
}
//mergelemeye karar verdiysem
if (ed[u].size()>ed[v].size()) swap(u,v);
while (ed[v].size()){
int it = ed[v].back();
ed[v].pop_back();
say[it][v]--;
it=find(it);
say[it][u]++;
ed[u].push_back(it);
say[u][it]++;
}
ed[v].clear();
sz[u]+=sz[v];
sz[v]=0;
par[v]=u;
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... |