POJ 1611 The Suspects
来源:互联网 发布:如何修改外网端口 编辑:程序博客网 时间:2024/06/08 01:11
题目大意:给你几个同学的集合,0为传染源,和他同组的都被传染,问有多少人被传染
最简单的并查集
结果忘了 if (rr1==rr2) return
RE了两次
#include<stdio.h>#include<stdlib.h>int parent[30001];int k;int findset(int x){ int tmp,s; s=x; while (parent[s]>=0) s=parent[s]; while (s!=x) { tmp=parent[x]; parent[x]=s; x=tmp; } return s;}void unionset(int r1,int r2){ int rr1,rr2; rr1=findset(r1); rr2=findset(r2); int tmp=parent[rr1]+parent[rr2]; if (rr1==rr2) return; if (parent[rr1]>parent[rr2]) { parent[rr1]=rr2; parent[rr2]=tmp; } else { parent[rr2]=rr1; parent[rr1]=tmp; } return;}int main(){ int a,b,n,m; scanf("%d%d",&n,&m); while (n!=0 || m!=0) { for (int i=0;i<=n;i++) parent[i]=-1; for (int i=1;i<=m;i++) { scanf("%d%d",&k,&a); for (int j=2;j<=k;j++) { scanf("%d",&b); unionset(a,b); } } printf("%d\n",-parent[findset(0)]); scanf("%d%d",&n,&m);}}
- POJ 1611 The Suspects
- poj 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ-1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 - The Suspects
- POJ 1611 The Suspects
- Poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 the suspects
- POJ 1611 The Suspects
- ubuntu11.10下opencv的各种问题小汇总
- 清除浮动的3种方法
- How can I get the local group name for guests/administrators?
- 【旧代码】fortran中的指针实现链表的代码
- ubuntu 下搭建node.js + express
- POJ 1611 The Suspects
- 收集的JS常用正则表达式等
- Qt Creator 2.3.1 产生 “/usr/bin/ld: .: No such file: File format not recognized”
- JavaScript可否多线程? 深入理解JavaScript定时机制
- Android - what's the difference between the various methods to get a Context?
- Lex&Yacc使用总结
- modscan36--my milestone
- 简历中需要删掉的词
- 愤怒的小鸟物理学:小黄鸟特性分析