标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1272
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34035 Accepted Submission(s): 10406
不需要用并查集,统计点的个数和线的条数,如果 点的个数 - 线的条数 = 1,则满足
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 100005 int main() { int a, b, k, m, i; bool vis[N]; while(~scanf("%d%d", &a, &b)) { k = m = 0; memset(vis, false, sizeof(vis)); if(a == -1 && b == -1) break; if(a == 0 && b == 0) { printf("Yes\n"); continue; } else { vis[a] = vis[b] = true; k++; } while(~scanf("%d%d", &a, &b)) { if(a == 0 && b == 0) break; vis[a] = vis[b] = true; k++; } for(i = 0 ; i < N ; i++) if(vis[i]) m++; if(m - k == 1) printf("Yes\n"); else printf("No\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4677236.html