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"
#define N_ 1502
int N;
struct unf{
int p[N_], c[N_];
int w[N_][N_];
void init(){for(int i=0;i<N;i++)p[i] = i, c[i] = 1;}
int Find(int x){return p[x] == x ? x : p[x] = Find(p[x]);}
int Union(int x,int y){
x = Find(x), y = Find(y);
if(w[x][y] == c[x] * c[y] - 1){
p[x] = y, c[y] += c[x];
for(int i=0;i<N;i++)w[y][i] += w[x][i], w[i][y] += w[i][x];
return 1;
}
w[x][y]++, w[y][x]++;
return 0;
}
}uf;
void initialize(int n) {
N = n;
uf.init();
}
int hasEdge(int u, int v) {
return uf.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... |