POJ 1611 The Suspects
来源:互联网 发布:淘宝模特快拍视频 编辑:程序博客网 时间:2024/04/30 01:47
http://poj.org/problem?id=1611
题目大意是0号同学感染了SARS,0~n-1号同学被分成了m组,相互接触就会被传染,问最后多少人感染。
娱乐身心的裸并查集,记得最后从0开始计数。。。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,ans;int fa[30010];int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}int main(){ scanf("%d%d",&n,&m); while(n!=0) { ans=0; for(int i=0;i<=n;i++) fa[i]=i; for(int i=1;i<=m;i++) { int k,x,y; scanf("%d",&k); scanf("%d",&x); for(int i=1;i<=k-1;i++) { scanf("%d",&y); int fx=find(x); int fy=find(y); fa[fx]=fy; } } for(int i=0;i<n;i++) if(find(0)==find(i)) ans++; printf("%d\n",ans); scanf("%d%d",&n,&m); } return 0;}
0 0
- 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
- mysql命令一些常用的选项
- poj1815
- JS弹出会话框中文乱码
- txypgx
- vi跳刀最后一行
- POJ 1611 The Suspects
- OC中的容器类及其功能方法:数组,字典,集合
- linux设置服务开机启动
- C&&C++ 经典书籍
- 将Mat图片加载到PictureControl控件中
- 到底是学Java还是.net
- 「能写代码」是愚公移山,「会写代码」是女娲补天
- 使用easyui-textbox, 点回车键,执行某个按钮的方法
- U盘问题,插入时只有声音,没有显示,在”计算机管理”的“磁盘管理”中,上面看不到盘符”H:”,下面可以看到”磁盘1 可移动无媒