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;
int n;
int am[1510][1510];
struct UF
{
int rep[1510];
void init()
{
for (int i = 0; i < n; i++) rep[i] = i;
}
int findrep(int a)
{
if (rep[a] == a) return a;
return rep[a] = findrep(rep[a]);
}
void merge(int a, int b)
{
a = findrep(a);
b = findrep(b);
rep[b] = a;
for (int i = 0; i < n; i++)
{
am[a][i] += am[b][i];
am[i][a] += am[b][i];
}
}
};
UF uf;
void initialize(int N) {
n = N;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++) am[i][j] = 1;
}
uf.init();
}
int hasEdge(int u, int v) {
int a = uf.findrep(u);
int b = uf.findrep(v);
if (a == b) { return 0; }
if (am[a][b] > 1)
{
am[a][b]--;
am[b][a]--;
return 0;
}
uf.merge(u, v);
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... |