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; ...
随机推荐
- 基于amoeba实现mysql数据库的读写分离/负载均衡
一.Amoeba的简述:[来自百度百科] Amoeba是一个以MySQL为底层数据存储,并对应用提供MySQL协议接口的proxy.它集中地响应应用的请求,依据用户事先设置的规则,将SQL请 ...
- linux 调度器配制参数
http://blog.csdn.net/wudongxu/article/details/8574753 参数位置: /proc/sys/kernel/ 编绎内核时参数 [root@monitor ...
- 【Linux学习笔记】用nc实现两台主机间的文件传输(不需要输密码)
通常,可以用scp完成两台主机间的文件传输任务,但在主机间未建立信任关系的情况下,scp每次都需要输入密码,用起来感觉不是很方便,之前这篇笔记介绍过不用输入密码执行脚本或传输文件的方法,但对于一些临时 ...
- SDL 实现透明悬浮窗
最近一直想用SDL实现弹幕功能,但是一直没法实现悬浮窗和透明背景功能. 在一个老外的博客上发现了思路:EthioProgrammer: Applying transparency using win3 ...
- 10.27 noip模拟试题
1.铺瓷砖(tile.cpp/c/pas)[问题描述]有一面很长很长的墙. 你需要在这面墙上贴上两行瓷砖. 你的手头有两种不同尺寸的瓷砖,你希望用这两种瓷砖各贴一行.瓷砖的长可以用分数表示,贴在第一行 ...
- SQL常用的语句和函数
order by 的数值型灵活使用 select * from table_a where order by decode(函数,'asc',1,'desc',-1)*jsny; 控制试图的访问时间: ...
- js的MVC结构设计
基于jquery的Deferred,设计出如下MVC架构. 模型model interface.js interface: function(userid){ var dtd = $.Deferred ...
- 第一篇、Apache和Tomcat的整合
1.web架构 首先上图,解释web通用架构 通常情况下分为三大块 : ★ Web server : 通常情况下由 Apache Http Server . IBM Http Server .I ...
- winows8.1或winows7 64bit 安装Itunes 64bit 11.1.3 无法打开一直停止工作的解决办法
winows8.1或winows7 64bit 安装Itunes 64bit 11.1.3 无法打开一直停止工作的解决办法 系统环境变量里的Path追加 ;C:\program files (x86) ...
- WebService开发步骤
WebService原理什么的百度很多我就说了,无非就是提供一个接口放在服务端,客户端实现这个接口就可以拿到自己需要的东西. 现在简单说一下用myEclipse来实现服务端和客户端.另一种WebSer ...