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;
struct DSU{
int n;
vector<int> lab;
void init(int _n){
n=_n;
lab.assign(n, -1);
}
int find_set(int u){
return lab[u]<0?u:lab[u]=find_set(lab[u]);
}
void union_sets(int u, int v){
u=find_set(u); v=find_set(v);
if (u!=v){
if (lab[u]>lab[v]) swap(u, v);
lab[u]+=lab[v];
lab[v]=u;
}
}
} dsu;
int n;
set<pair<int, int>> edge;
void initialize(int n_) {
n=n_;
for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) edge.emplace(i, j);
}
int hasEdge(int u, int v) {
dsu.init(n);
if (u>v) swap(u, v);
edge.erase({u, v});
for (auto &i:edge) dsu.union_sets(i.first, i.second);
if (dsu.lab[dsu.find_set(0)]+n){
edge.emplace(u, v);
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... |