poj1611(感染病患者)
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 24587 | Accepted: 12046 |
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
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int m,n;
int a[30005];
int b[30005];
int pd[30005];
void update()
{
for(int i=0; i<n; i++)
a[i]=i;
}
int get(int x)
{
if(a[x]!=x)
a[x]=get(a[x]);
return a[x];
}
void unin(int x,int y)
{
a[get(y)]=get(x);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
memset(b,0,sizeof(b));
memset(pd,0,sizeof(pd));
memset(a,0,sizeof(a));
update();
for(int i=1; i<=m; i++)
{
int ans;
scanf("%d",&ans);
for(int j=1; j<=ans; j++)
{
scanf("%d",&b[j]);
if(pd[b[j]]==0)
pd[b[j]]=1;
if(j!=1)
unin(b[j-1],b[j]);
}
}
int sum=0;
if(m==0)
printf("1\n");
else
{
for(int i=1; i<=30005; i++)
{
if(pd[i]==1&&get(i)==get(0))
sum++;
}
printf("%d\n",sum+1);
}
}
return 0;
}
poj1611(感染病患者)的更多相关文章
- poj1611 The Suspects(并查集)
题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...
- “冰桶挑战”之外:微软科技助力ALS患者
编者按:"直到ALS出现治疗方法,科技就是我的解药."ALS患者,前美国橄榄球联盟(NFL)球员Steve Gleason如是说.最近,一支微软首届黑客马拉松(Hackathon) ...
- 使用HTML5开发Kinect体感游戏
一.简介 我们要做的是怎样一款游戏? 在前不久成都TGC2016展会上,我们开发了一款<火影忍者手游>的体感游戏,主要模拟手游章节<九尾袭来 >,用户化身四代,与九尾进行对决, ...
- Windows on Device 项目实践 2 - 感光灯制作
在上一篇<Windows on Device 项目实践 1 - PWM调光灯制作>中,我们学习了如何利用Intel Galileo开发板和Windows on Device来设计并完成一个 ...
- 【CityHunter】基于LBS的AR体感游戏设计理念
本人目前还不是游戏行业的圈内人士,并不懂得,游戏行业的生态圈,也不懂得,所谓的什么“中国市场环境”.所以不敢发表关于这方面的见解,不过我在这里想要插一句话,就是我认为啊,行业内,人与人之间还是有分层次 ...
- MWeb 2.0 测试版可以下载啦,这次是公开测试,感兴趣的朋友可以试试
2.0 版是 MWeb 发布以来,最重要的一个版本.MWeb 自去年一月份发布以来,获得了很多朋友的建议,在此非常感谢!没有你们,2.0 版可能就不能出来!然后再次感谢 Producter: http ...
- Kinect外包团队(长年承接微软Kinect体感项目外包,有大型Kinect案例)
承接Kinect体感企业项目.游戏项目外包 北京公司.专业团队,成员为专业WPF产品公司一线开发人员,有大型产品开发经验: 提供优质的售后服务,保证产品质量,轻量级产品可以提供规范清晰的源代码,有业务 ...
- java 并发性和多线程 -- 读感 (一 线程的基本概念部分)
1.目录略览 线程的基本概念:介绍线程的优点,代价,并发编程的模型.如何创建运行java 线程. 线程间通讯的机制:竞态条件与临界区,线程安全和共享资源与不可变性.java内存模型 ...
- windows 8.1 试用感受:蛋疼感大幅降低
众所周知windows 8 的最大使用感受就是蛋疼. 无论是微软MVP,还是我这样的万年不悔微软小白鼠,普通用户,小白用户,或多或少的都对这款操作系统感到蛋疼. 槽点太多,以至于大家都懒得批判了.好在 ...
随机推荐
- 09.C#委托转换和匿名方法(五章5.1-5.4)
今天将书中看的,自己想的写出来,供大家参考,不足之处请指正.进入正题. 在C#1中开发web form常常会遇到使用事件,为每个事件创建一个事件处理方法,在将方法赋予给事件中,会使用new Event ...
- javascript基础知识拾遗
1 下面列出的值被当作假 false null undefined '' 0 NaN 其它所有值被当作是真 console.log(undefined || true); //true console ...
- 关于js字符串替换的一道笔试题目
题目描述 请写出一个字符串转换函数,接受两个参数: 1.字符串 形如{a}ab-{b}cde{c}fff{d}{}: 2.对象,形如{'a':'1','b':'2','d':'4'} 根据,对象的属性 ...
- 调研Android平台开发环境的发展演变
Android是Google推出的开源手机操作系统,主要以开发应用为主,要进行Android开发首先得搭建好开发平台.最近在搭建Android的开发环境,发现往往一个小问题都能花费你大半天时间,从刚开 ...
- [转]Oracle中的索引详解
原文地址:http://www.oschina.net/question/30362_4057 一. ROWID的概念 存储了row在数据文件中的具体位置:64位 编码的数据,A-Z, a-z, 0- ...
- 5.9-3 用正则表达式判断字符串text是否为合法的手机号
package zfc; public class Zfc { public static void main(String[] args) { //判断手机号格式是否合法 String text = ...
- AMD&CMD
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java基础-四要素之一《继承》
继承的概念: 继承在本职上是特殊——一般的关系,即常说的is-a关系.子类继承父类,表明子类是一种特殊的父类,并且具有父类所不具有的一些属性或方法. 继承是所有OOP语言不可缺少的部分,在java中使 ...
- GCC、Makefile编程学习
相关学习资料 http://gcc.gnu.org/ https://gcc.gnu.org/onlinedocs/ http://zh.wikipedia.org/zh/GCC http://blo ...
- Codeforces 578B "Or" Game
传送门 B. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...