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>
typedef long long ll;
using namespace std;
int noedge[1515][1515], sz[1515], path[1515], h[1515], N;
int dis_find(int s){
if (s==path[s]) return s;
return path[s]=dis_find(path[s]);
}
void dis_merge(int s1, int s2){
int v1=dis_find(s1), v2=dis_find(s2);
if (h[v1]>h[v2]) swap(v1, v2);
path[v1]=v2;
if (h[v1]==h[v2]) h[v2]++;
sz[v2] += sz[v1];
for (int i=0;i<N;i++){
noedge[v2][i] += noedge[v1][i];
noedge[i][v2] += noedge[i][v1];
}
}
void initialize(int n) {
N=n;
for (int i=0;i<N;i++){
sz[i]=1;
path[i]=i;
}
}
int hasEdge(int u, int v) {
int x=dis_find(u), y=dis_find(v);
assert(x!=y);
if (sz[x]*sz[y]-1==noedge[x][y]){
dis_merge(x, y);
return 1;
}
noedge[x][y]++, noedge[y][x]++;
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... |