poj-1611-The Suspects
2018-06-17 23:45:19来源:未知 阅读 ()
Time Limit: 1000MS | Memory Limit: 20000K | |
Total Submissions: 34284 | Accepted: 16642 |
Description
In the Not-Spreading-Your-Sickness University (NSYSU), there are many student groups. Students in the same group intercommunicate with each other frequently, and a student may join several groups. To prevent the possible transmissions of SARS, the NSYSU collects the member lists of all student groups, and makes the following rule in their standard operation procedure (SOP).
Once a member in a group is a suspect, all members in the group are suspects.
However, they find that it is not easy to identify all the suspects when a student is recognized as a suspect. Your job is to write a program which finds all the suspects.
Input
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.
Output
Sample Input
100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
200 2
1 5
5 1 2 3 4 5
1 0
0 0
Sample Output
4
1
1
题目大意:找0所在集合的成员个数
题目链接:http://poj.org/problem?id=1611
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int f[30008];
int num[30008];
int find(int n)
{
if(n!=f[n])
f[n]=find(f[n]);
return f[n];
}
int main()
{ int n,m;
while(cin>>n>>m)
{ if(n==0&&m==0)
break;
for(int i=0;i<n;i++)
{f[i]=i;num[i]=1;}
int a,b,c;
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
for(int j=1;j<a;j++)
{
scanf("%d",&c);
int b1=find(b),c1=find(c);
if(b1!=c1)
{
f[c1]=b1;
num[b1]+=num[c1];
}
}
}
cout<<num[find(0)]<<endl;
}
return 0;
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- SGU 132 Another Chocolate Maniac 2020-03-06
- 协程的原理(Coroutine Theory) 2020-02-23
- 二叉堆(2)LeftistHeap 2020-02-19
- Boost C++ 库 中文教程(全) 2019-12-19
- Run-Time Check Failure #0 - The value of ESP was not pro 2019-11-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash