hdu 1878

时间:2022-01-30 16:04:08

http://acm.hdu.edu.cn/showproblem.php?pid=1878

题意:就是判断这个图是不是一个欧拉回路的一个题,

思路:我觉得这个题可以用并查集判环加上判断每个点的度就行了

 #include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
int graph[];
int belg[]; int Find(int x)
{
int _x=x,_b;
while( _x != belg[ _x ] )
_x = belg[ _x ];
while( x != belg[ x ] )
{
_b = belg[ x ];
belg[ x ] = _x;
x = _b;
}
return _x;
} void unio(int x,int y)
{
int root1 = Find(x);
int root2 = Find(y);
if( root1 != root2 ) belg[root2] = root1;
} int main()
{
int n,m,a,b;
while(scanf("%d",&n)&&n)
{
int falg = ,mark;
scanf("%d",&m);
memset(graph,false,sizeof(graph));
for(int i = ; i <= n ; i++)
belg[i] = i;
for(int i = ; i <= m ; i++ )
{
scanf("%d%d",&a,&b);
unio(a,b);
graph[a]++;
graph[b]++;
}
mark = belg[];
for(int i = ; i <= n ; i++)
{
if(belg[i]!=mark||(graph[i]&)) {
falg = ;
break;
}
}
if(falg) printf("1\n");
else printf("0\n");
}
}