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 N = 1500;
int sz[N];
int p[N];
int eBetween[N][N];
int n;
int getRoot(int node)
{
if (p[node] == node) return node;
p[node] = getRoot(p[node]);
return p[node];
}
void initialize(int n1) {
n = n1;
for (int i = 0; i < n; i++)
{
p[i] = i;
sz[i] = 1;
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
eBetween[i][j] = 1;
eBetween[j][i] = 1;
}
}
}
int hasEdge(int u, int v) {
u = getRoot(u);
v = getRoot(v);
if (eBetween[u][v] == 1)
{
if (sz[u] < sz[v])
{
swap(u, v);
}
sz[u] += sz[v];
for (int i = 0; i < n; i++)
{
int num = eBetween[v][i];
eBetween[u][i] += num;
eBetween[i][u] += num;
}
p[v] = u;
return 1;
} else
{
eBetween[u][v]--;
eBetween[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... |