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; ...
随机推荐
- 习WebSocket一(WebSocket初识)[转]
http://www.cnblogs.com/wgp13x/p/3812579.html Java EE 7 去年刚刚发布了JSR356规范,使得WebSocket的Java API得到了统一,Tom ...
- StopWatch的用法
在学习spring的时候,看到关于统计时间的类,比较好奇,就记录下来,以便以后用到可以直接使用 org.springframework.util.StopWatch StopWatch该类在统计时间的 ...
- oracle 字符串切割成结果集方法
oracle字符串切割几种方式 方法一: SELECT COLUMN_VALUE FROM TABLE(SYS.ODCIVARCHAR2LIST('1','2','3','4','5')); 方法二: ...
- css3 calc()
概述 CSS函数calc()可以用在任何一个需要<length>的地方.有了calc(),你可以通过计算来决定一个对象的大小和形状. 你还可以在一个calc()内部嵌套另一个calc(). ...
- js--小结⑦---格式转换
- GridView 无数据时,绑定提示
private void BindData() { DataTable dt = DAO.RunSQLReturnDt(this.getsql()); int dtcount = dt.Rows.Co ...
- VisualStudio2013&VS2015内置SQLServer入门 (三)
关于LocalDB的部署(publish): 使用本机做服务器(目测不可行) 双击项目的Properties-->Publish-->Application Files,你会发现没有.md ...
- 你好,C++(2)1.3 C++世界版图1.4 如何学好C++
1.3 C++世界版图 C++语言的发展过程,不仅是一个特性不断增加.内容不断丰富的过程,更是一个在应用领域中不断攻城略地的过程.在其30余年的发展过程中,C++在多个应用领域都得到了广泛的应用和发 ...
- java dos下中文乱码
代码如下: public class PrintString{ public static void main(String args[]){ System.out.println("\\* ...
- 读终端输入数据BufferedReader
public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStream ...