POJ1611(KB2-B)
The Suspects
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 39211 | Accepted: 18981 |
Description
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
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.
Output
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
//2017-07-19
#include <iostream> using namespace std; const int N = ;
int n, m, fa[N]; void init(){
for(int i = ; i < N; i++)
fa[i] = i;
} int getfa(int x){
if(x == fa[x])return x;
else return fa[x] = getfa(fa[x]);
} void merge0(int a, int b){
int af = getfa(a);
int bf = getfa(b);
if(af != bf)
fa[bf] = af;
} int main(){
while(cin>>n>>m){
if(!n && !m)break;
init();
int k, a, b;
while(m--){
cin>>k>>a;
for(int i = ; i < k-; i++){
cin>>b;
merge0(a, b);
}
}
int ans = ;
for(int i = ; i < n; i++){
if(getfa(i) == fa[])
ans++;
}
cout<<ans<<endl;
} return ;
}
POJ1611(KB2-B)的更多相关文章
- 并查集 poj1611&poj2492
poj1611 简单题 代码中id记录父节点,sz记录子树规模.一个集合为一棵树. #include <iostream> #include <cstdio> using na ...
- poj1611 The Suspects(并查集)
题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...
- poj1611(并查集)
题目链接:http://poj.org/problem?id=1611 题意: SARS(非典型肺炎)传播得非常厉害,其中最有效的办法是隔离那些患病.和患病者接触的人.现在有几个学习小组,每小组有几个 ...
- poj1611 并查集 (路径不压缩)
http://poj.org/problem?id=1611 题目大意: 有一个学校,有N个学生,编号为0-N-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染,并且这些人如果还参加了别的社 ...
- poj1611(感染病患者)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24587 Accepted: 12046 De ...
- poj1611 带权并查集
题意:病毒蔓延,现在有 n 个人,其中 0 号被认为可能感染,然后给出多个社交圈,如果某个社交圈里有人被认为可能被感染,那么所有这个社交圈里的人都被认为可能被感染,现在问有多少人可能被感染. 带权并查 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- poj1611 并查集
题目链接:http://poj.org/problem?id=1611 #include <cstdio> #include <cmath> #include <algo ...
- poj1611 简单并查集
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 32781 Accepted: 15902 De ...
随机推荐
- HTML textares的使用
<textarea>标签定义及用法 在html中,<textarea>标签是用来定义一个多行的文本输入控件,在文本输入域中可以输入任意长度的文本.文本默认字体是等宽字体(Cou ...
- saltstack returners 结果转存
returners 是saltstack对minion执行操作后,对返回的数据进行存储,可以存储到一个文件或者数据库当中. 支持的returners http://docs.saltstack.cn/ ...
- 【LeetCode】547. 朋友圈
题目 班上有 N 名学生.其中有些人是朋友,有些则不是.他们的友谊具有是传递性.如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友.所谓的朋友圈,是指所有朋友的集 ...
- Eclipse的使用与Oblect类的常用方法_DAY11
一.Java开发工具的使用 A:notepad windows自带的记事本. B:高级记事本 Editplus Notepad++ UE sublime2 C:集成开发工具(IDE) 开发和运行. E ...
- c++的动态绑定和静态绑定
为了支持c++的多态性,才用了动态绑定和静态绑定. 1.对象的静态类型:对象在声明时采用的类型.是在编译期确定的. 2.对象的动态类型:目前所指对象的声明.在运行期决定.对象的动态类型可以更改,但是静 ...
- SSH远程连接Ubuntu Server
Ubuntu默认没有安装openssh-server包,故从远程计算机通过SSH连接时会收到Connection refused的消息. 首先在Ubuntu检查/etc/ssh/sshd_config ...
- 【Canal源码分析】client工作过程
client的工作过程,需要我们自己去编写对应的逻辑,我们目前只能从example写的例子来看.目前examle中提供了两个例子,一个是单机的,一个是集群的cluster,我们后续如果需要进行开发的话 ...
- Android_触摸事件传递机制
Android中dispatchTouchEvent,onInterceptTouchEvent, onTouchEvent的理解ecandroid中的事件类型分为按键事件和屏幕触摸事件,Touch事 ...
- 全网最详细的Windows系统里PLSQL Developer 64bit的下载与安装过程(图文详解)
不多说,直接上干货! ORACLE是数据库,有客户端和服务器: 其,具体下载,可见http://www.oracle.com/technetwork/database/enterprise-editi ...
- Gen类的字符串操作
public void t(String d){ final String str = "b"; String s = "a"+"c"+st ...