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>
#include "game.h"
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int n;
const int N=100;
int pa[N],sz[N],g[N],vis[N][N];
vector<int>v[N];
void merge(int x,int y)
{
if(sz[x]<sz[y])swap(x,y);
for(auto it:v[y])
{
pa[it]=x;
v[x].pb(it);
sz[x]++;
}
v[y].clear();
}
void go(int x)
{
memset(g,0,sizeof g);
int r=0,re=0;int w=-1;
for(int i=0;i<n;i++)
{
if(pa[i]==x)continue;
for(auto it:v[x])
{
if(vis[it][i])continue;
if(g[pa[i]])re++;
g[pa[i]]=1;
w=pa[i];
}
}
if(w==-1)return;
if(re>1)return;
merge(x,w);
}
void initialize(int N) {
n=N;
for(int i=0;i<n;i++)
{
v[i].pb(i);
pa[i]=i;
sz[i]=1;
}
}
int hasEdge(int x, int y) {
if(pa[x]==pa[y]){
vis[x][y]=1;
return 1;}
int xx=x,yy=y;
x=pa[x];y=pa[y];int r=0,rr=0;
for(auto it:v[x])
{
for(int i=0;i<n;i++)
{
int u=pa[i];
if(u==x)continue;
if(vis[it][i])continue;
if(i==yy&&it==xx)continue;
r=1;break;
}
}
for(auto it:v[y])
{
for(int i=0;i<n;i++)
{
int u=pa[i];
if(u==y)continue;
if(vis[it][i])continue;
if(i==xx&&it==yy)continue;
rr=1;
}
}
if(r>0&&rr>0)
{
vis[xx][yy]=1;
vis[yy][xx]=1;
go(x);
go(y);
return 0;
}
merge(x,y);
return 1;
}
/*
4
0 1
0 2
0 3
3 1
1 2
3 2
*/
Compilation message (stderr)
game.cpp: In function 'void go(int)':
game.cpp:26:9: warning: unused variable 'r' [-Wunused-variable]
26 | int r=0,re=0;int w=-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... |