The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 25149   Accepted: 12329

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

Source

题解:合并集合
代码:使用并查集
#include<iostream>
using namespace std;
int father[];
int input[];
int find(int n)
{
if(father[n]!=n)
father[n]=find(father[n]);
return father[n];
}
void merge(int a,int b)
{
int x,y;
x=find(a);
y=find(b);
if(x!=y)
father[x]=y;
}
int main()
{
int n,m,k,num;
int i,j;
while()
{ cin>>n>>m;
for(i=; i<n; i++)
father[i]=i;
if(n==&&m==)
break;
while(m--)
{
cin>>num;
for(i=; i<num; i++)
cin>>input[i];
for(i=; i<num; i++)
merge(input[],input[i]);
}
int cnt=;
for(i=; i<n; i++)
if(find(father[])==find(father[i]))
cnt++;
cout<<cnt<<endl;
}
return ;
}

POJ_1611_The Suspect的更多相关文章

  1. MS SQLServer 2008数据库处于SUSPECT情况下的处理

    做任何恢复操作之前,请先备份.mdf, .ndf和.ldf文件. use master go --将处于suspect状态下的数据库设置为紧急状态 alter database <Databas ...

  2. DataBase异常状态:Recovery Pending,Suspect,估计Recovery的剩余时间

    一,RECOVERY PENDING状态 今天修改了SQL Server的Service Account的密码,然后重启SQL Server的Service,发现有db处于Recovery Pendi ...

  3. Take advantage of “Integrated Calling” to know whom suspect talked to

    A new feature in iOS 10 is "Integrated Calling". An integrated call from Chat App like Nav ...

  4. Database Corruption ->> Fix Database In Suspect State

    昨天在工作中遇到一个情况,就是Development环境中的某台服务器上的某个数据库进入了Suspect状态.以前看书倒是知道说这个状态,不过实际工作当中从来没有遇到过.那么一些背景情况是这样的. 环 ...

  5. MS SQL 数据库状态为SUSPECT(可疑)的处理方法

    原文出处:http://www.cnblogs.com/kerrycode/archive/2013/06/10/3131360.html 当SQL SERVER数据库状态为质疑(SUSPECT)状态 ...

  6. 当DATABASE进入了suspect模式以后

    一个VM的错误就造成了sql2012的脱序.很多一般看不到的模式陆续登场 诸如 recovery pending, suspect, EMERGENCY. 以下脚本可以帮助恢复,如果文件没有损坏的话. ...

  7. DB异常状态:Recovery Pending,Suspect,估计Recovery的剩余时间

    一,RECOVERY PENDING状态 今天修改了SQL Server的Service Account的密码,然后重启SQL Server的Service,发现有db处于Recovery Pendi ...

  8. 解决数据库SUSPECT(置疑)状态

    在虚拟机中运行数据库不小心强制关机了,结果有一个重要的数据库后面加上了一个suspect的关键字,在管理器中打不开,程序也不能运行. 网上有很多分析的方法,试了一些不管用,最后用这种方法解决了,记录一 ...

  9. Creating, detaching, re-attaching, and fixing a SUSPECT database

    今天遇到一个问题:一个数据库suspect了.然后又被用户detach了. 1,尝试将数据库attach回去,因为log file损坏失败了. 2,尝试将数据库attach回去,同一时候rebuild ...

随机推荐

  1. iOS自己定义返回button(不影响返回手势)

    此方法能够自己定义返回button,且不影响返回手势. 新方法: self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] in ...

  2. Linux bash: scp: command not found的问题记录

    ,总结 scp成功,须要两个server都安装了scp服务才行.

  3. hdu 5001 概率DP 图上的DP

    http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题  一则有一个点难以想到 二则就是编码有 ...

  4. Netty In Action中文版 - 第四章:Transports(传输)

    本章内容 Transports(传输) NIO(non-blocking IO,New IO), OIO(Old IO,blocking IO), Local(本地), Embedded(嵌入式) U ...

  5. [办公自动化]如何让excel图表标签中显示最新值数据

    同事做了一张excel图表,希望最新的数据显示数据标签,其他都不显示.并且当单元格的数据新增加时,这个标签要能自动更新. 这里需要用到公式,获取到这个最新值.在b2输入公式=lookup(9e+307 ...

  6. Lucas模板&快速幂模板

    /* *********************************************** Author :guanjun Created Time :2016/5/20 0:28:36 F ...

  7. JSSDK使用步骤

    绑定域名 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 备注:登录后可在“开发者中心”查看对应的接口权限. 引入js文件 在需要调用JS接口的页面引入如下JS文件,( ...

  8. 为了一个句号,写了好多行的代码——值!(html 表单的处理)

    个人信息表 <span style="font-size:18px;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...

  9. E20170527-ts

    asset   n. 资产,财产; 有价值的人或物; 有用的东西; 优点; serializer  [词典] 串行(化)器(把并行数据变成串行数据的寄存器); 编程语言中,可被序列化的; inflec ...

  10. bzoj4890[Tjoi2017]城市(树的半径)

    4890: [Tjoi2017]城市 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 149  Solved: 91[Submit][Status][D ...