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 <bits/stdc++.h>
#define MAXN 1510
#define inf 1e9
using namespace std;
int edge[MAXN][MAXN],N,d[MAXN];
int Root(int p)
{
while (d[p]!=p)
{
d[p]=d[d[p]];
p=d[p];
}
return p;
}
void Join(int p,int q)
{
d[Root(p)]=d[Root(q)];
}
void initialize(int n)
{
N=n;
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
edge[i][j]=-1;
edge[i][i]=1;
d[i]=i;
}
}
bool Check(int u,int v)
{
vector<int> c;
for (int i=0;i<N;i++)
{
if (Root(i)==Root(u) && i!=v)
c.push_back(i);
}
for (int i : c)
{
for (int j=0;j<N;j++)
{
if (j!=u && j!=v && edge[v][j] && edge[j][i])
return false;
}
}
return true;
}
int hasEdge(int u, int v)
{
if (Check(u,v) || Check(v,u))
{
edge[u][v]=1;
edge[v][u]=1;
Join(u,v);
return 1;
}
edge[u][v]=0;
edge[v][u]=0;
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... |