hdu 1325 Is It A Tree?
来源:互联网 发布:cin c语言怎么用 编辑:程序博客网 时间:2024/05/16 08:45
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int M = 1005;int vist[M], Set[M];int du[M];int a, b, maxn;int flag, cont, k;/*形成树的条件是, 每一个节点的入度只能为1, 且根只能有一个。*/int Find(int x) { return x == Set[x]? x : Set[x] = Find(Set[x]);}void Union(int x, int y) { x = Find(x); y = Find(y); if(x != y) { Set[y] = x; }}void init() { for(int i = 1; i < M; i++) { Set[i] = i; vist[i] = 0; du[i] = 0; } flag = 1; cont = 0; k = 0; maxn = 0;}int main(){ int q = 1; init(); while(scanf("%d%d", &a, &b) != EOF) { if(a < 0 && b < 0) break; if(a == 0 && b == 0) { for(int i = 1; i < M; i++) { if(vist[i] && Set[i] == i) { cont++; } if(du[i] > 1) { flag = 0; break; } } if(cont >1) flag = 0; if(flag) printf("Case %d is a tree.\n", q++); else printf("Case %d is not a tree.\n", q++); flag = 0; init(); continue; } if(a != b && Find(a) == Find(b)) { flag = 0; } else { vist[a] = 1; vist[b] = 1; du[b]++; Union(a, b); } } return 0;}
0 0
- HDU 1325 Is It a Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 is it a tree?
- HDU-1325-Is It A Tree?
- HDU 1325 Is It A Tree? ---树
- HDU 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is It A Tree?
- hdu 1325 Is it a tree
- hdu 1325 &&poj1308 Is It A Tree?
- HDU 1325 Is It A Tree?
- HDU 1325 Is It A Tree?
- HDU 1325 Is It A Tree?
- hdu 1325 is it a tree?
- android适配器
- John's trip
- 配置自己的vim-常用插件
- access "update语句的语法错误"解决
- 九度OJ 1015
- hdu 1325 Is It A Tree?
- 动态规划——最长公共子序列(LCS)&最长递增子序列(LIS)
- 电子商务商业模式实训及思考 第一问
- Canvas类
- XML保存HTML页面的下拉列表内容
- ubuntu下Firefox 更新flash出现的小问题
- JavaScript性能优化
- spring学习笔记1——部分基础及概念
- TopCoder SRM 144 DIV1 BinaryCode