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"
#define DIM 1510
using namespace std;
int n,i,t[DIM],a[DIM][DIM];
int get_rad (int x){
while (t[x] > 0)
x = t[x];
return x;
}
int hasEdge(int x, int y){
x++, y++;
int radx = get_rad(x), rady = get_rad(y);
if (radx == rady)
return 1;
a[radx][rady]++, a[rady][radx]++;
if (a[radx][rady] == (-t[radx]) * (-t[rady])){
/// acum ar trebui sa unesc padurile astea
if (t[radx] > t[rady])
swap (radx,rady);
t[radx] += t[rady];
t[rady] = radx;
/// trb sa actualizez matricea a
for (int i=1;i<=n;i++){
if (radx == i)
continue;
a[radx][i] += a[rady][i];
a[i][radx] += a[rady][i];
}
return 1;
}
return 0;
}
void initialize (int N){
n = N;
for (i=1;i<=n;i++)
t[i] = -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... |