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 <stdio.h>
int Cut[1505][1505];
int P[1505], Sz[1505];
int N;
int UF(int u)
{
return (P[u] == -1)?u:(P[u] = UF(P[u]));
}
void initialize(int n)
{
N = n;
int i;
for (i = 0; i < n; i++)
{
P[i] = -1;
Sz[i] = 1;
}
}
int hasEdge(int u, int v)
{
int pu = UF(u);
int pv = UF(v);
int i;
// printf("Cut %d Sz %d %d\n", Cut[pu][pv], Sz[pu], Sz[pv]);
if (Cut[pu][pv] + 1 == Sz[pu]*Sz[pv])
{
P[pu] = pv;
for (i = 0; i < N; i++)
{
Cut[pv][UF(i)] += Cut[pu][UF(i)];
Cut[pu][UF(i)] = 0;
Cut[UF(i)][pv] = Cut[pv][UF(i)];
}
Sz[pv] += Sz[pu];
return 1;
}
Cut[pu][pv]++;
Cut[pv][pu]++;
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... |