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>res;
struct DSU{
vector<int>parent,sz;
DSU(int n){
parent.resize(n);
sz.resize(n,1);
iota(parent.begin(),parent.end(),0);
}
int findsets(int v){
if (v == parent[v]){
return v;
}
parent[v] = findsets(parent[v]);
return parent[v];
}
bool unionset(int u,int v){
u = findsets(u);
v = findsets(v);
if (u == v){
return false;
}
if (sz[v] > sz[u]){
swap(u,v);
}
parent[v] = u;
sz[u]+=sz[v];
return true;
};
};
DSU st(1501);
void initialize(int n) {
res.resize(n,n - 1);
}
int hasEdge(int u, int v) {
if (st.findsets(u) == st.findsets(v))return 1;
if ((res[u] == 1 && res[v] >= 1) || (res[v] == 1 && res[u] >= 1)){
st.unionset(u,v);
res[u]--;
res[v]--;
}
return st.findsets(u) == st.findsets(v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |