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>
//#include<game.h>
using namespace std;
const int NAX = 1505;
int N;
int P[NAX] , sz[NAX];
int used[NAX][NAX];
void make_set(){
for(int i = 0; i < N; ++i){
P[i] = i;
sz[i] = 1;
}
}
int Find(int x){
return (P[x] == x) ? x : P[x] = Find(P[x]);
}
int Union(int u , int v){
int U = Find(u);
int V = Find(v);
int edges = sz[U] * sz[V];
int x = (sz[U] >= sz[V]) ? U : V;
int y = (sz[U] < sz[V]) ? U : V;
++used[x][y];
++used[y][x];
if(edges == used[x][y]){
sz[x] += sz[y];
P[y] = x;
for(int i = 0; i < N; ++i){
used[x][i] += used[y][i];
used[i][x] += used[i][y];
}
return 1;
}
return 0;
}
void initialize(int n){
N = n;
make_set();
}
int hasEdge(int u , int v){
return Union(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... |