The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 34284   Accepted: 16642

Description

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others. 
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

The input file contains several cases. Each test case begins with two integers n and m in a line, where n is the number of students, and m is the number of groups. You may assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 is recognized as a suspect in all the cases. This line is followed by m member lists of the groups, one line per group. Each line begins with an integer k by itself representing the number of members in the group. Following the number of members, there are k integers representing the students in this group. All the integers in a line are separated by at least one space. 
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.

Output

For each case, output the number of suspects in one line.

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;
}
 

poj-1611-The Suspects的更多相关文章

  1. 【原创】poj ----- 1611 The Suspects 解题报告

    题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K To ...

  2. poj 1611 The Suspects 解题报告

    题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...

  3. poj 1611 The Suspects(简单并查集)

    题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...

  4. POJ - 1611 The Suspects 【并查集】

    题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...

  5. 【裸的并查集】POJ 1611 The Suspects

    http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...

  6. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

  7. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

  8. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

  9. poj 1611 The Suspects 并查集

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 30522   Accepted: 14836 De ...

  10. POJ 1611 The Suspects (并查集)

    The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...

随机推荐

  1. atitit  验证码理论与概览与 验证码规范 解决方案.docx

    atitit  验证码理论与概览与 验证码规范 解决方案.docx 1.1. 验证码的前世今生1 1.2. 第三代:无知识型验证码1 1.3. 短信验证码1 1.4. 语言验证码1 1.5. 图片验证 ...

  2. Atitit usrqbg1834 html的逻辑化流程化 规范标准化解决方案

    Atitit usrqbg1834 html的逻辑化流程化 规范标准化解决方案 常用指令1 ..v-if.v-else指令2 v-for指令3 MVVM大比拼4 常用指令 本来按照Vue文档说明,常用 ...

  3. G2 DT时代的图形语法 正式发布

    G2有一个高大上的名字叫做:The Grammar Of Graphics——图形语法.它是一个强大的语义化图表生成工具,它提供了一整套图形语法,可以让用户通过简单的语法搭建出无数种图表,并且集成了大 ...

  4. 【译】采用MVC模式创建一个简单的javascript App

    原文标题:Build A Simple Javascript App The MVC Way 作者:joshcrawmer4 翻译人:huansky 初次翻译,翻译的不好,还请见谅 JavaScrip ...

  5. Jetty 服务器的知识

    Jetty 服务器的知识 也许你还没有听说过这个Jetty服务器,不过它确实是一种比较轻量级的Java服务器,和Tomcat一样,专门解释JavaWeb程序的服务器.因为在之前学习Java Web 的 ...

  6. 浅谈Winform事件的实现以及模拟其事件的实现(附实现源码)

    当我们初学Winform的时候被其神奇的事件功能所吸引,当点击一个按钮时,便会跳到我们所写的点击方法当中去.然而这并不符合我们对方法的理解,究竟.net在后面帮助我们实现了什么.我们怎样模拟其事件的实 ...

  7. [转载]UML类图总结

    前言 类图和序列图是UML中最常用的两种Diagram.我将做详细的总结.在许多书中,或者网站中,在介绍一个系统的子系统的设计时,很多时候,都是给出简单的类图来简述构成子系统的类之间的关系.这足以说明 ...

  8. Windows 8(虚拟机环境)安装.NET Framework3.5(includes .NET 2.0 and 3.0)

    按照这篇文章:http://blogs.technet.com/b/aviraj/archive/2012/08/04/windows-8-enable-net-framework-3-5-inclu ...

  9. 创建支持多种屏幕尺寸的Android应用

    Android涉及各种各样的支持不同屏幕尺寸和密度的设备.对于应用程序,Android系统通过设备和句柄提供了统一的开发环境,大部分工作是校正每一个应用程序的用户界面到它显示的屏上.与此同时,系统提供 ...

  10. C# 控制台或者winform程序开启http的监听状态

    1 public class THttpListener { HttpListener listerner; /// <summary> /// /// </summary> ...