POJ-1611 The Suspects
来源:互联网 发布:360全景效果图软件 编辑:程序博客网 时间:2024/06/18 09:32
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=66964#problem/B
题目大意:有N个人其中0号患有SARS,有M个小组,一个小组中若有一个病人则全组患病,最后询问N个人中有几人患病。
解题思路:并查集简单应用,将每一组中的人合并,最后找和0号在一个联通块的人就行。入门级。
(PS:最近要把OI的知识找回来,更新不会太频繁且按分类从简单题开始)
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<cstdlib>#include<algorithm>using namespace std;const int maxn=30005;int fa[maxn];int n,m,ans;int find(int x){if(fa[x]==x) return x;else return fa[x]=find(fa[x]);} int main(){while(scanf("%d%d",&n,&m)!=EOF){if(n==0&&m==0) break; for(int i=0;i<n;i++) fa[i]=i; int num,player1,player2; for(int i=1;i<=m;i++){ scanf("%d",&num); scanf("%d",&player1); for(int j=1;j<num;j++){ scanf("%d",&player2); fa[find(player2)]=find(player1);//注意要加find(); } }ans=0;for(int i=0;i<n;i++) if(find(0)==find(i)) ans++; cout<<ans<<endl;} 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
- CListCtrl透明完美实现
- 手机淘宝APP主要视觉设计图分析【惠龙之 :花骨朵儿】
- CTreeCtrl背景透明完美实现
- Windows 7 64位 HookApi例子
- Java中keySet()返回值的排序问题
- POJ-1611 The Suspects
- Struts2学习笔记
- [leetcode] 230. Kth Smallest Element in a BST
- 【2014.8.17NOIP普及组模拟】愤怒的牛
- 关于Java生成指定格式的xml文档
- Java中的final和static
- 一致性性哈希
- [转]易语言 360免杀方法心得总结
- 【MVC5】2.添加控制器