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>
using namespace std;
const int MAXN = 1510;
int n;
int par[MAXN], siz[MAXN], no[MAXN][MAXN];
int f(int x){
if(par[x]==x) return x;
return par[x] = f(par[x]);
}
bool con(int x, int y){
x = f(x); y = f(y);
return x==y;
}
void mer(int x, int y){
x = f(x); y = f(y);
if(con(x, y)) return;
if(siz[x] < siz[y]) swap(x, y);
par[y] = x;
siz[x] += siz[y];
for(int i=1; i<=n; i++){
int num = no[i][y];
if(i > y) num = no[y][i];
if(i < x) no[i][x] += num;
else no[x][i] += num;
}
}
void initialize(int N) {
n = N;
for(int i=1; i<=n; i++){
par[i] = i;
siz[i] = 1;
}
}
int hasEdge(int u, int v) {
u++; v++;
if(con(u, v)) return 0; // udh connected
u = f(u); v = f(v);
if(u > v) swap(u, v);
if(no[u][v] == siz[u] * siz[v] - 1){
mer(u, v); // tinggal 1 doang
return 1;
}
// masi lebih dari 1
no[u][v]++;
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... |