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;
#define MAXN 1500
int parent[MAXN],height[MAXN];
int rem[MAXN][MAXN];
int N;
int find_set(int v){
if(parent[v]==v) return v;
else return parent[v]=find_set(parent[v]);
}
bool is_connected(int a,int b){
return find_set(a)==find_set(b);
}
void union_sets(int a,int b){
a=find_set(a);
b=find_set(b);
if(a==b) return;
if(height[a]<height[b]) swap(a,b);
parent[b]=a;
if(height[a]==height[b]) height[a]++;
for(int i=0;i<N;i++){
rem[a][i]+=rem[b][i];
rem[i][a]+=rem[i][b];
}
}
void initialize(int n) {
N=n;
for(int i=0;i<n;i++){
parent[i]=i;
height[i]=0;
for(int j=0;j<n;j++){
if(i==j) continue;
rem[i][j]=1;
}
}
}
int hasEdge(int u, int v) {
u=find_set(u);
v=find_set(v);
if(u==v){
return 1;
}else{
if(rem[u][v]>1){
rem[u][v]--;
rem[v][u]--;
return 0;
}else{
union_sets(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... |