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<iostream>
#include "game.h"
using namespace std;
static int n;
static int a[1505][1505], r[1505], num[1505];
static int rad(int x){
while(r[x] >= 0){
x = r[x];
}
return x;
}
void initialize(int N) {
n = N;
for(int i = 0; i < n; i++){
r[i] = -1;
num[i] = 1;
}
}
int hasEdge(int x, int y) {
int r1, r2, i;
r1 = rad(x);
r2 = rad(y);
if(r1 == r2){
return 1;
}
if(r[r1] > r[r2]){
swap(r1, r2);
}
if(a[r1][r2] != num[r1] * num[r2] - 1){
a[r1][r2]++;
a[r2][r1]++;
return 0;
}
r[r1] += r[r2];
num[r1] += num[r2];
r[r2] = r1;
for(i = 0; i < n; i++){
a[r1][i] += a[r2][i];
a[i][r1] = a[r1][i];
}
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |