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>
using namespace std;
int a,b,n,size[1506],road[1506][1506],parent[1506];
void make_sets(){
for(int k=0;k<n;k++)
{
parent[k]=k;
size[k]=1;
for(int i=0;i<n;i++)
if(i!=k)
road[i][k]=1,
road[k][i]=1;
}
}
int find_set(int u){
if(u==parent[u]) return u;
parent[u]=find_set(parent[u]);
return parent[u];
}
int union_set(int m,int p ){
int x=find_set(m);
int y=find_set(p);
if(road[x][y]>1){
road[x][y]--;
road[y][x]--;
return 0;
}
if(size[x]<size[y]) swap(x,y);
parent[y]=x;
size[x]+=size[y];
for(int k=0;k<n;k++){
if(parent[k]!=x)
{
road[k][x]+=road[k][y];
road[x][k]=road[k][x];
}
}
return 1;
}
void initialize(int N){
n=N;
make_sets();
}
int hasEdge(int u, int v){
int b=union_set(u,v);
return b;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |