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 = 1505;
int par[MAXN];
int comp[MAXN][MAXN];
int n;
int find(int v)
{
if(par[v] == v)
return v;
return par[v] = find(par[v]);
}
void merge(int f, int s)
{
f = find(f), s = find(s);
if(f == s)
return;
if(f > s)
swap(f, s);
par[s] = f;
for(int i = 1; i <= n; i++)
{
if(i == f)
continue;
int old = comp[f][i];
comp[f][i] = old + comp[s][i];
comp[i][f] = old + comp[i][s];
}
}
void initialize(int total) {
n = total;
for(int i = 1; i <= n; i++)
{
par[i] = i;
for(int j = 1; j <= n; j++) {
comp[i][j] = (i != j ? 1 : 0);
//cout << i << " " << j << " " << comp[i][j] << "\n";
}
}
}
int hasEdge(int u, int v) {
u++;
v++;
if(comp[find(u)][find(v)] == 1) {
merge(u, v);
return 1;
}
else {
comp[find(u)][find(v)]--;
comp[find(v)][find(u)]--;
return 0;
}
return 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... |