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;
vector<int> sz;
vector<int> pp;
vector<int> sz2;
vector<int> pp2;
vector<pair<int,int>> edge;
int find(int id, vector<int>& pp)
{
if(pp[id] != id)
{
pp[id] = find(pp[id],pp);
}
return pp[id];
}
bool unite(int a,int b,vector<int>& sz, vector<int>& pp)
{
if(a==b) return false;
a = find(a,pp);
b = find(b,pp);
if (a==b) return false;
if(sz[a] < sz[b]) swap(a,b);
pp[b] = a;
sz[a] += sz[b];
return true;
}
void initialize(int n) {
for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) edge.push_back({j,i});
pp.resize(n);
iota(pp.begin(),pp.end(),0);
sz.assign(n,1);
}
int hasEdge(int u, int v) {
if (u > v) swap(u,v);
sz2 = sz;
pp2 = pp;
*find(edge.begin(),edge.end(),pair<int,int>{u,v}) = {0,0};
for(auto i : edge) unite(i.first,i.second,sz2,pp2);
if(find(u,pp2)==find(v,pp2)) return 0;
unite(u,v,sz,pp);
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... |