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 <iostream>
#include <numeric>
#include <vector>
#include <set>
using namespace std;
vector<set<int>> can;
vector<int> par;
int get(int x){
if(par[x] != x){
return par[x] = get(par[x]);
}
return x;
}
void merge(int u, int v){
par[u] = v;
}
void initialize(int N){
par.resize(N);
set<int> con;
for(int i = 0; i < N; i ++){
con.insert(i);
}
can.resize(N);
for(int i = 0; i < N; i ++){
con.erase(i);
can[i] = con;
con.insert(i);
}
iota(par.begin(), par.end(), 0);
}
int hasEdge(int u, int v){
u = get(u);
v = get(v);
if(u == v){return 0;}
can[u].erase(v);
can[v].erase(u);
if(can[u].size() == 0){
merge(u, v);
return 1;
}
if(can[v].size() == 0){
merge(v, u);
return 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... |