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. 水晶报表 Crystal Report 调用存储过程时出错 找不到表 ,解决方法。

    用 CrystalReportViewer1 控件在asp.net的网页上显示报表,假设做报表时调用数据表数据的方式调用是能够成功的.但报表是用存储过程获取数据方式会出现下面错误: 找不到表'RptO ...

  2. js 返回顶部

    <script> window.onload = function(){ var oTop = document.getElementById("to_top"); v ...

  3. 60分钟Python快速学习

    之前和同事谈到Python,每次下班后跑步都是在听他说,例如Python属于“胶水语言啦”,属于“解释型语言啦!”,是“面向对象的语言啦!”,另外没有数据类型,逻辑全靠空格缩进表示等. 今天自己用了6 ...

  4. POJ 3100:Root of the Problem

    Root of the Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12060   Accepted: 6 ...

  5. win10设置锁屏时间

    这里应该修改成自己希望的分钟数  比如120分钟

  6. DNS中的AC、rndc、智能DNS解析和基础排错

    bind中的ACL和rndc DNS除了服务器外,还具有一些访问控制和视图功能. 访问控制是指仅对定义的网络进行解析,视图也就是智能解析. 1>访问控制是通过acl函数来实现的,acl把一个或多 ...

  7. 深入浅出Android makefile(2)--LOCAL_PATH(转载)

    转自:http://nfer-zhuang.iteye.com/blog/1752387 一.说明 上文我们对acp的Android.mk文件做了一个大致的描述,使得大家对Android.mk文件有了 ...

  8. Google C++编程规范 – 第十九条 -《前置声明》

    转自:http://roclinux.cn/?p=3285 本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc wu == [规范] ...

  9. Unity资源的查找

    Object.Destroy static function Destroy(obj: Object, t: float = 0.0F): void;   Description Removes a ...

  10. bzoj1528 sam-Toy Cars(贪心,优先队列)

    「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...