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;
#define pii pair <int,int>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
const int N = 2e3 + 100;
int cnt[N][N],sz[N],dsu[N],n;
bool ex[N];
int getroot(int v) {
return dsu[v] == v ? v : dsu[v] = getroot(dsu[v]);
}
void merg(int v,int u) {
v = getroot(v);
u = getroot(u);
if(v == u)return;
dsu[u] = v;
ex[u] = 0;
for(int j = 0;j < n;j++) {
if(!ex[j] || j == v)continue;
cnt[v][j] += cnt[u][j];
cnt[j][v] += cnt[j][u];
}
sz[v] += sz[u];
}
/*
4
0 1
3 0
1 2
0 2
3 1
2 3
*/
void initialize(int N) {
n = N;
for(int i = 0;i < n;i++) {
dsu[i] = i;
sz[i] = 1;
ex[i] = 1;
}
}
int hasEdge(int u, int v) {
u = getroot(u);
v = getroot(v);
if(cnt[v][u] + 1 == sz[v] * sz[u]) {
merg(v,u);
return 1;
}else {
cnt[v][u]++;
cnt[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... |