The Suspects(简单的并查集)
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 就是看看有几个人可能患病,从 0开始传播;100 是总人数,4是组数,下面每行开头是组的人数,后面是人的编号,简单并查集;庆幸没超时
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int a,k,m,n,p,s[],i,h,sum;
while(~scanf("%d %d",&m,&n))
{
if(!m&&!n)break;
memset(s,,sizeof(s));
for(i=; i<n; i++)
{
scanf("%d",&p);
while(p--)
{
scanf("%d",&a);
if(s[a])
{
h=s[a];
for(k=; k<m; k++)
{
if(s[k]==h)
s[k]=i+;
}
}
s[a]=i+;
}
}
if(s[]==)
printf("1\n");
else
{
sum=;
for(i=; i<m; i++)
if(s[i]==s[])
sum++;
printf("%d\n",sum);
}
}
return ;
}
Hint
Five cows with milk outputs of 1..5
OUTPUT DETAILS:
1 and 2 are below 3; 4 and 5 are above 3.
The Suspects(简单的并查集)的更多相关文章
- The Suspects 简单的并查集
Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not ...
- hdu 1182 A Bug's Life(简单种类并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 题意:就是给你m条关系a与b有性关系,问这些关系中是否有同性恋 这是一道简单的种类并查集,而且也 ...
- poj 1611 :The Suspects经典的并查集题目
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- 【POJ】The Suspects(裸并查集)
并查集的模板题,为了避免麻烦,合并的时候根节点大的合并到小的结点. #include<cstdio> #include<algorithm> using namespace s ...
- UVA - 1160(简单建模+并查集)
A secret service developed a new kind of explosive that attain its volatile property only when a spe ...
- hdu 1213 (How Many Tables)(简单的并查集,纯模板)
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ——1611The Suspects(启发式并查集+邻接表)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 31100 Accepted: 15110 Descri ...
- [原]poj-1611-The Suspects(水并查集)
题目链接:http://poj.org/problem?id=1611 题意:输入n个人,m个组.初始化0为疑似病例.输入m个小组,每组中只要有一个疑似病例,整组人都是疑似病例.相同的成员可以在不同的 ...
- 1213 How Many Tables 简单的并查集问题
my code: #include <cstdio>#include <cstring>#include<iostream>using namespace std; ...
随机推荐
- webservice传递特殊字符时的解决的方法
webservice soap报文是xml格式交互的,当中针对特殊字符传递无法解析,导致数据处理失败. 解决的方法例如以下: 1.在发送报文之前,针对报文进行base64转码,转义后避免报文中含有特殊 ...
- wdlinux 编译pdo_mysql
由于项目需要用到pdo 链接数据库 wdlinux在centos6.4下 没有pdomysql模块 ,所以重新编译 有的系统无法使用pdo_mysql 1 重新编译mysql http://www.w ...
- POCISO-採购创建内部订单(R12.2.3)
採购创建内部订单(R12.2.3) --US Program:Create Internal Orders Short Name:POCISO Application:Purchasing Ex ...
- HDU 1025 Constructing Roads In JGShining's Kingdom (DP)
Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which ...
- 用 Qt 中的 QDomDocument类 处理 XML 文件(下)
QDomDocument doc; 1).创建根节点:QDomElement root = doc.documentElement("rootName " ); 2).创建元素 ...
- freemarker if..else.. 的使用
FreeMarker是一款模板引擎,今天在做Pad端的时候正好用到,用法非常简单: 在xml配置页面的文件中,直接使用 <#if 1=1> //条件成立要显示的内容 </#if> ...
- css考核点整理(三)-css选择器的使用
css选择器的使用
- 自己做的萌萌哒的js宠物挂件~
OwO萌物v1.1 类似wp伪春菜,但纯js不用后端,且可定制程度非常高~,3个人格示例,需要的童鞋自提 仙六 - 越祈 作者:正逍遥0716 2016/5/15 CLANNAD - 藤林杏 作者:正 ...
- (转)修改ECSHOP前后台的title中的ecshop
前台部分: 1:去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop 前者在后台商店设置 - 商店标题修改 后者打开includes/lib_main.php $page_t ...
- MVC+EF 的增删改查操作
1. //创建EF映射对象数据集 static Models.db_JiaoYouEntities DbDeleteData = new Models.db_JiaoYouEntities(); 2. ...