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<bits/stdc++.h>
using namespace std;
struct DSU{
vector<int> v;
vector<vector<int>> deg;
void init(int n){v.assign(n, -1); deg.assign(n, vector<int>(n, 0));}
int get(int x){return v[x] < 0 ? x : v[x] = get(v[x]);}
int unite(int x, int y){
x = get(x); y = get(y);
if(x == y) return 0;
deg[x][y]++; deg[y][x]++;
if(deg[x][y] != v[x] * v[y]) return 0;
if(v[x] > v[y]) swap(x, y);
v[x] += v[y]; v[y] = x;
for(int i = 0; i < (int)v.size(); i++){
if(v[i] < 0){
deg[i][x] += deg[i][y];
deg[x][i] += deg[y][i];
}
}
return 1;
}
};
DSU UF;
void initialize(int n){
UF.init(n);
}
int hasEdge(int u, int v){
return UF.unite(u, 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... |