标签:sync size 整数 欧拉路径 script == tput ios otto
Problem Description
欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路?
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
int d[maxn];
using namespace std;
int par[maxn];
int num[maxn];
void init()
{
for(int i=0;i<maxn;i++)
par[i]=i,num[i]=1;
}
int find(int x)
{
if(par[x]!=x)
par[x]=find(par[x]);
return par[x];
}
void Union(int x,int y)
{
int xx=find(x);
int yy=find(y);
if(xx!=yy){
par[xx]=yy;
num[yy]+=num[xx];
}
}
int main(){
int n,m;
ios::sync_with_stdio(false);
while(1){
cin>>n;
if(n==0) return 0;
cin>>m;
init();
memset(d,0,sizeof(d));
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
Union(a,b);
d[a]++;
d[b]++;
}
bool f=1,g=0;
for(int i=1;i<=n;i++){
if( d[i]%2==1) f=0; //存在奇数点
if( num[i]==n ) g=1; //表示连通
}
if( f && g ) cout<<"1"<<endl;
else cout<<"0"<<endl;
}
return 0;
}
标签:sync size 整数 欧拉路径 script == tput ios otto
原文地址:https://www.cnblogs.com/lyj1/p/11371586.html