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,还是我这样的万年不悔微软小白鼠,普通用户,小白用户,或多或少的都对这款操作系统感到蛋疼. 槽点太多,以至于大家都懒得批判了.好在 ...
随机推荐
- [USACO2005][POJ3044]City Skyline(贪心+单调栈)
题目:http://poj.org/problem?id=3044 题意:以坐标的形式给出一张图,表示一些楼房的正视图,求出楼房的最少个数. 分析:和小学常做的立方体问题很像,很容易想到一个贪心方法, ...
- Missing message for key "err1" in bundle "(default bundle)" for locale zh_CN
这个问题是: 你的使用了ApplicationResources_zh_CN.properties文件没有找到. 1.是struts-config.xml中的<message-resources ...
- js库中$冲突的解决方法
http://www.w3school.com.cn/jquery/core_noconflict.asp
- hdu1358 KMP
求循环节. #include<stdio.h> #include<string.h> #define maxn 1000010 int next[maxn]; char s[m ...
- Java基础-String、StringBuffer、StringBuilder
看下面这段代码: public class Main { public static void main(String[] args) { String string = ""; ...
- CAS做单点登陆(SSO)——集成BIEE 11g
BIEE 11G和CAS集成零代码编写,只需配置. 更改BIEE analytics应用的web.xml 将analytics.war解包(使用7-zip或者Win-rar就可以),然后修改WEB-I ...
- java初学的分析
java初学的分析第一阶段:入门阶段学习目标:简单项目开发学习内容:1.Java入门书籍,Java基础知识.关于Java入门级的书,给大家推荐过<Java编程思想>.<Java核心技 ...
- nginx&apache比较
1.nginx相对于apache的优点: 轻量级,同样起web 服务,比apache占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx ...
- 简短的几句js实现css压缩和反压缩功能
写在前面 最近一直在整理css,但因为现在Visual Studio 2013太智能了,它每每在我按ctrl+E+D进行格式化代码的时候,就会将css进行层次格式化(如下图所示),而这个格式让我老大实 ...
- poj1787Charlie's Change(多重背包+记录路径+好题)
Charlie's Change Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3720 Accepted: 1125 ...