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. android自己定义控件系列教程----视图

    理解android视图 对于android设备我们所示区域事实上和它在底层的绘制有着非常大的关系,非常多时候我们都仅仅关心我们所示,那么在底层一点它究竟是怎么样的一个东西呢?让我们先来看看这个图. w ...

  2. 【智能路由器】让MT7620固件openwrt支持USB

    [智能路由器]系列文章连接 http://blog.csdn.net/u012819339/article/category/5803489 首先确定硬件有USB,这个得检查板子是否引出了usb口,一 ...

  3. 进程间通信之-共享内存Shared Memory--linux内核剖析(十一)

    共享内存 共享内存是进程间通信中最简单的方式之中的一个. 共享内存是系统出于多个进程之间通讯的考虑,而预留的的一块内存区. 共享内存同意两个或很多其他进程訪问同一块内存,就如同 malloc() 函数 ...

  4. c# 获取根节点的属性信息

    <?xml version="1.0" encoding="UTF-8"?> <!--课程封面信息 --> <GK version ...

  5. EL 隐含对象

    EL     隐含对象(11个):

  6. 简述Python中的break和continue的区别

    众所周知在Python中,break是结束整个循环体,而continue则是结束本次循环再继续循环. 但是作为一个新手的你,还是不明白它们的区别,这里用一个生动的例子说明它们的区别,如下: 1.con ...

  7. 5. extjs 中buttonAlign什么意思

    转自:https://zhidao.baidu.com/question/1174901985976576339.html指定Panel中按钮的位置.可配置的值有'right', 'left' 和 ' ...

  8. Rails5入门

    更新: 2017/05/29 更新: 2017/09/07 补充对ruby自身的扩张的放置位置  配置文件位置  /config/routes.rb  最简单的定义方法  get ('hello/in ...

  9. SVG Path标签 A 参数

    A rx ry x-axis-rotation large-arc-flag sweep-flag x yrx:x轴半径ry:y轴半径x-axis-rotation:指椭圆的X轴与水平方向顺时针方向夹 ...

  10. 11.7NOIP模拟题

    /* 有循环节 */ #include<cstdio> #include<cstring> #include<iostream> #include<algor ...