杭电hdu 1878 欧拉回路 无向图
2012-05-08 19:54
295 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1878
无向图的欧拉回路。
判断一个无向图是否存在欧拉回路,只需判断这个无向图连通并且每个顶点的度为偶数。
无向图的欧拉回路。
判断一个无向图是否存在欧拉回路,只需判断这个无向图连通并且每个顶点的度为偶数。
#include <stdio.h> #include <string.h> int degree[1001]; int father[1001]; int map[1001][1001]; int n; void init() { int i; memset(map, 0, sizeof(map)); for(i = 0; i <= n; i ++){ father[i] = i; degree[i] = 0; } } int getfather(int x) { while(x != father[x]){ x = father[x]; } return x; } void join(int x, int y) { int fa = getfather(x); int fb = getfather(y); if(fa != fb)father[fb] = fa; } int main() { int m, i, from, to; int cir; while(scanf("%d", &n)&&n){ init(); scanf("%d", &m); while(m --){ scanf("%d%d", &from, &to); if(map[from][to] == 0){ map[from][to] = map[to][from] = 1; degree[from] ++; degree[to] ++; join(from, to); } } cir = 0; for(i = 1; i <= n; i ++){ if(father[i] == i){ cir ++; } } if(cir != 1)printf("0\n"); else { for(i = 1; i <= n; i ++){ if(degree[i] % 2 != 0)break; } if(i > n){ printf("1\n"); } else printf("0\n"); } } return 0; }
相关文章推荐
- hdu 1878 欧拉回路 无向图连通性
- hdu 1878 欧拉回路(无向图)
- HDU 1878 无向图判欧拉回路
- 【欧拉回路(无向图判定)】hdu 1878 欧拉回路
- HDU 1878 欧拉回路
- HDU 1878 无向图的欧拉回路的判断
- hdu 1878 欧拉回路
- HDU 1878 欧拉回路
- hdu 1878 欧拉回路
- HDU 1878 欧拉回路(欧拉回路)
- HDU 1878.欧拉回路
- hdu 1878 欧拉回路
- HDU 1878:欧拉回路【并查集】
- HDU - 1878 欧拉回路
- hdu 1878 欧拉回路
- hdu1878 欧拉回路
- 【HDU-1878】 欧拉回路
- HDU-1878 欧拉回路(DFS)(并查集)
- HDU 1878 欧拉回路(并查集+欧拉回路)
- 杭电Problem1878 欧拉回路 并查集 + 欧拉回路