The Suspects POJ1611
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 36417 | Accepted: 17681 |
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
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int pre[],num[];
int findn(int x)
{
if(x!=pre[x])
pre[x] = findn(pre[x]);
return pre[x];//注意这里是pre[x]
}
void join(int x,int y)
{
int fx=findn(x),fy=findn(y);
if(fx!=fy)
{
if(num[fx]>=num[fy])
{
pre[fy] = fx;
num[fx] = num[fx] + num[fy];//跟新num
}
else
{
pre[fx] = fy;
num[fy] = num[fy] + num[fx];
}
}
}
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
if(n==&&m==)
break;
for(int i=;i<n;i++)
pre[i]=i,num[i]=;//先初始化
while(m--)
{
int a,b;
scanf("%d %d",&a,&b);
for(int i=;i<a;i++)
{
int c;
scanf("%d",&c);
join(b,c);//以每组第一个建立一个小组集合
}
}
printf("%d\n",num[pre[]]);
}
return ;
}
The Suspects POJ1611的更多相关文章
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- POJ1611:The Suspects(模板题)
http://poj.org/problem?id=1611 Description Severe acute respiratory syndrome (SARS), an atypical pne ...
- poj1611 The Suspects(并查集)
题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- POJ1611 The Suspects (并查集)
本文出自:http://blog.csdn.net/svitter 题意:0号学生染病,有n个学生,m个小组.和0号学生同组的学生染病,病能够传染. 输入格式:n,m 数量 学生编号1,2,3,4 ...
- POJ1611 The Suspects 并查集模板题
题目大意:中文题不多说了 题目思路:将每一个可能患病的人纳入同一个集合,然后遍历查找每个点,如果改点点的根节点和0号学生的根节点相同,则该点可能是病人. 模板题并没有思路上的困难,只不过在遍历时需要额 ...
- poj1611 The suspects【并查集】
严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not-Spreading-Y ...
- POJ1611(The Suspects)--简单并查集
题目在这里 关于SARS病毒传染的问题.在同一个组的学生是接触很近的,后面也会有新的同学的加入.其中有一位同学感染SARS,那么该组的所有同学得了SARS.要计算出有多少位学生感染SARS了.编号为0 ...
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
随机推荐
- vue3.0中的双向数据绑定方法
熟悉vue的人都知道在vue2.x之前都是使用object.defineProperty来实现双向数据绑定的 而在vue3.0中这个方法被取代了 1. 为什么要替换Object.definePrope ...
- 2019前端面试系列——HTTP、浏览器面试题
浏览器存储的方式有哪些 特性 cookie localStorage sessionStorage indexedDB 数据生命周期 一般由服务器生成,可以设置过期时间 除非被清理,否则一直存在 页面 ...
- HttpClientFactory 使用说明 及 对 HttpClient 的回顾和对比
目录 HttpClient 日常使用及坑点: HttpClientFactory 优势: HttpClientFactory 使用方法: 实战用法1:常规用法 1. 在 Startup.cs 中进行注 ...
- Linux学习之自动配置部署——初用expect
主机A连接主机B 免密登陆 + 自动部署 expect实现自动的交互式任务 ——— send 向进程发送字符串(输入) ——— expect 从进程接受字符串 ——— spawn 启动新进程 ——— ...
- GitHub项目:jkrasnay/sqlbuilder的使用
http://www.jianshu.com/p/7f099b8cf5f0 技术选型: 在报表查询时,通常需要做可以动态添加的条件 在老项目中使用的是一种Tcondition的对象分装sql impo ...
- ABAP 金额转换成大写
FUNCTION zzfi_change_amount.*"---------------------------------------------------------------- ...
- 【KakaJSON手册】05_JSON转Model_05_动态模型
在上一篇文章中提到:有时候服务器返回的某个字段的内容类型可能是不确定的 当时给出的解决方案是实现kk_modelValue或者kk_didConvertToModel方法,根据实际需求自定义JSON的 ...
- Docker之- 使用Docker 镜像和仓库
目录 使用Docker 镜像和仓库 什么是 Docker 镜像 列出 Docker 镜像 tag 标签 Docker Hub 拉取镜像 查找镜像 构建镜像 创建Docker Hub 账号 使用 Doc ...
- Java反射Reflect的使用详解
目录 一. 什么是反射 二. 反射的基础Class 2.1 Class类概述 2.2 Class类对象获取的三种方式 三. 反射-构造函数 3.1 getDeclaredConstructor(Cla ...
- Kafka 系列(五)—— 深入理解 Kafka 副本机制
一.Kafka集群 Kafka 使用 Zookeeper 来维护集群成员 (brokers) 的信息.每个 broker 都有一个唯一标识 broker.id,用于标识自己在集群中的身份,可以在配置文 ...