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 <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <assert.h>
using namespace std;
typedef pair<int,int> pii;
int dsu[2010],rem[2010],N,cnt,number;
multiset< pii > st[2010];
int find(int u){
return dsu[u] == u ? u : dsu[u] = find(dsu[u]);
}
void initialize(int n) {
N = n;
number = n;
for (int i = 0; i < n; ++i){
dsu[i] = i;
rem[i] = n-1;
for(int j = 0 ; j < n ; j++){
if(j == i)
continue;
st[i].insert(make_pair(i,j));
}
}
}
bool check(int a){
return st[a].size() == 1 && st[find((*st[a].begin()).second)].size() == 1;
}
int hasEdge(int u, int v) {
cnt++;
int a = find(u);
int b = find(v);
if(a == b){
return 0;
}
st[a].erase(make_pair(u,v));
st[b].erase(make_pair(v,u));
bool can = st[a].size() == 0 || st[b].size() == 0;
can = can || check(a);
can = can || check(b);
if(can){
for(set<pii>::iterator it = st[b].begin();it != st[b].end();it++){
pii cur = *it;
if(st[a].find(make_pair(cur.second,cur.first)) != st[a].end())
continue;
st[a].insert(cur);
}
dsu[b] = a;
return true;
}
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... |