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 N = 1500 + 5;
int cnt[N][N], ran[N], p[N], siz[N];
bool ok[N];
int nn;
int fin(int a) {
if(p[a] == a) return a;
else return p[a] = fin(p[a]);
}
void mer(int a, int b) {
if(ran[a] < ran[b]) swap(a,b);
if(ran[a] == ran[b]) ran[a]++;
p[b] = a;
}
void initialize(int n) {
int nn = n;
for(int i = 0; i < n; i++) {
p[i] = i;
siz[i] = 1;
}
}
int hasEdge(int u, int v) {
u = fin(u); v = fin(v);
cnt[u][v]++; cnt[v][u]++;
for(int i = 0; i < nn; i++) ok[i] = 0;
if(siz[u]*siz[v] == cnt[u][v]) {
mer(u,v);
int x = fin(u);
siz[x] = siz[u]+siz[v];
for(int i = 0; i < nn; i++) {
int y = fin(i);
if(ok[y] == 1) continue;
ok[y] = 1;
cnt[x][y] = cnt[u][y] + cnt[v][y];
cnt[y][x] = cnt[x][y];
}
return 1;
}
else {
return 0;
}
}
Compilation message (stderr)
game.cpp: In function 'void initialize(int)':
game.cpp:18:9: warning: unused variable 'nn' [-Wunused-variable]
18 | int nn = n;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |