http://acm.hdu.edu.cn/showproblem.php?pid=1878
题意:就是判断这个图是不是一个欧拉回路的一个题,
思路:我觉得这个题可以用并查集判环加上判断每个点的度就行了
1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 using namespace std; 5 int graph[1005]; 6 int belg[1005]; 7 8 9 int Find(int x) 10 { 11 int _x=x,_b; 12 while( _x != belg[ _x ] ) 13 _x = belg[ _x ]; 14 while( x != belg[ x ] ) 15 { 16 _b = belg[ x ]; 17 belg[ x ] = _x; 18 x = _b; 19 } 20 return _x; 21 } 22 23 void unio(int x,int y) 24 { 25 int root1 = Find(x); 26 int root2 = Find(y); 27 if( root1 != root2 ) belg[root2] = root1; 28 } 29 30 int main() 31 { 32 int n,m,a,b; 33 while(scanf("%d",&n)&&n) 34 { 35 int falg = 1,mark; 36 scanf("%d",&m); 37 memset(graph,false,sizeof(graph)); 38 for(int i = 1 ; i <= n ; i++) 39 belg[i] = i; 40 for(int i = 1 ; i <= m ; i++ ) 41 { 42 scanf("%d%d",&a,&b); 43 unio(a,b); 44 graph[a]++; 45 graph[b]++; 46 } 47 mark = belg[1]; 48 for(int i = 1 ; i <= n ; i++) 49 { 50 if(belg[i]!=mark||(graph[i]&1)) { 51 falg = 0; 52 break; 53 } 54 } 55 if(falg) printf("1 "); 56 else printf("0 "); 57 } 58 }