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 <iostream>
#define MAXN 2000
int N;
int cross[MAXN][MAXN];
int par[MAXN];
int root(int u)
{
if(par[u] < 0)
return u;
par[u] = root(par[u]);
return par[u];
}
void merge(int u, int v)
{
if(par[u] > par[v])
u ^= v ^= u ^= v;
par[u] += par[v];
par[v] = u;
for(int i = 0; i < N; i++)
{
cross[u][i] += cross[v][i];
cross[i][u] = cross[u][i];
}
}
void initialize(int n)
{
N = n;
for(int i = 0; i < N; i++)
par[i] = -1;
}
int hasEdge(int u, int v)
{
int x = root(u);
int y = root(v);
if(cross[x][y] + 1 == par[x]*par[y])
{
merge(x, y);
return 1;
}
else
{
cross[x][y]++;
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... |