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 MAX = 1550;
int n, pai[MAX], sze[MAX], f[MAX][MAX];
int find(int u){
return pai[u] = (pai[u] == u ? u : find(pai[u]));
}
void join(int u, int v){
u = find(u), v = find(v);
if(u == v) return;
if(sze[v] > sze[u]) swap(u, v);
pai[v] = u; sze[u] += sze[v];
for(int i = 1; i <= n; i++)
f[u][i] += f[v][i], f[i][u] += f[v][i];
}
void initialize(int _n){
n = _n;
for(int i = 1; i <= n; i++){
pai[i] = i; sze[i] = 1;
for(int j = i + 1; j <= n; j++)
f[i][j] = f[j][i] = 1;
}
}
int hasEdge(int u, int v){
u++, v++;
u = find(u), v = find(v);
if(u == v) return 0;
if(f[u][v] == 1){ join(u, v); return 1; }
f[u][v]--, f[v][u]--;
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... |