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. yarn-cli 添加

    添加依赖包 当你想使用另一个包时,你要先把它添加到依赖列表中.也就是执行 yarn add [package-name] 命令将它安装到你的项目中. 这也将同时更新你的 package.json 和  ...

  2. 从epoll构建muduo-13 Reactor + ThreadPool 成型

    mini-muduo版本号传送门 version 0.00 从epoll构建muduo-1 mini-muduo介绍 version 0.01 从epoll构建muduo-2 最简单的epoll ve ...

  3. java并发编程之Semaphore

    信号量(Semaphore).有时被称为信号灯.是在多线程环境下使用的一种设施, 它负责协调各个线程, 以保证它们可以正确.合理的使用公共资源. 一个计数信号量.从概念上讲,信号量维护了一个许可集.如 ...

  4. linux redis tmp redis 安装

    Redis https://redis.io/download yum install make gcc gcc-c++ openssl-devel zlib-devel -y; wget tar - ...

  5. POJ 1330 LCA裸题~

    POJ 1330 Description A rooted tree is a well-known data structure in computer science and engineerin ...

  6. MySQL 基础 —— 数据类型、各种变量

    1. 基本数据类型 char:prod_id char(10),括号内的内容表示字符的长度 decimal:十进制,不带参数为整数(四舍五入) text:文本类型,长度不限 2. 日期和时间处理函数 ...

  7. GCD总结(一)

    GCD为我们提供了三种类型的调度队列(dispatch queue),分别为串行,并行和主调度队列. 串行(Serial)     你可以创建任意个数的串行队列,每个队列依次执行添加的任务,一个队列同 ...

  8. 洛谷 P2678 [ NOIP 2015 ] 跳石头 —— 二分答案

    题目:https://www.luogu.org/problemnew/show/P2678 二分答案. 代码如下: #include<iostream> #include<cstd ...

  9. gerrit+gitlab整合调试

  10. bzoj 1690: [Usaco2007 Dec]奶牛的旅行【01分数规划+spfa】

    把add传参里的double写成int我也是石乐志-- 首先这个东西长得就很01分数规划 然后我不会证为什么没有8字环,我们假装他没有 那么设len为环长 \[ ans \leq \frac{\sum ...