The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 24587   Accepted: 12046

Description

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.
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

The input file contains several cases. Each test case begins with two integers n and m in a line, where n is the number of students, and m is the number of groups. You may assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 is recognized as a suspect in all the cases. This line is followed by m member lists of the groups, one line per group. Each line begins with an integer k by itself representing the number of members in the group. Following the number of members, there are k integers representing the students in this group. All the integers in a line are separated by at least one space.
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.

Output

For each case, output the number of suspects in one line.

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(感染病患者)的更多相关文章

  1. poj1611 The Suspects(并查集)

    题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...

  2. “冰桶挑战”之外:微软科技助力ALS患者

    编者按:"直到ALS出现治疗方法,科技就是我的解药."ALS患者,前美国橄榄球联盟(NFL)球员Steve Gleason如是说.最近,一支微软首届黑客马拉松(Hackathon) ...

  3. 使用HTML5开发Kinect体感游戏

    一.简介 我们要做的是怎样一款游戏? 在前不久成都TGC2016展会上,我们开发了一款<火影忍者手游>的体感游戏,主要模拟手游章节<九尾袭来 >,用户化身四代,与九尾进行对决, ...

  4. Windows on Device 项目实践 2 - 感光灯制作

    在上一篇<Windows on Device 项目实践 1 - PWM调光灯制作>中,我们学习了如何利用Intel Galileo开发板和Windows on Device来设计并完成一个 ...

  5. 【CityHunter】基于LBS的AR体感游戏设计理念

    本人目前还不是游戏行业的圈内人士,并不懂得,游戏行业的生态圈,也不懂得,所谓的什么“中国市场环境”.所以不敢发表关于这方面的见解,不过我在这里想要插一句话,就是我认为啊,行业内,人与人之间还是有分层次 ...

  6. MWeb 2.0 测试版可以下载啦,这次是公开测试,感兴趣的朋友可以试试

    2.0 版是 MWeb 发布以来,最重要的一个版本.MWeb 自去年一月份发布以来,获得了很多朋友的建议,在此非常感谢!没有你们,2.0 版可能就不能出来!然后再次感谢 Producter: http ...

  7. Kinect外包团队(长年承接微软Kinect体感项目外包,有大型Kinect案例)

    承接Kinect体感企业项目.游戏项目外包 北京公司.专业团队,成员为专业WPF产品公司一线开发人员,有大型产品开发经验: 提供优质的售后服务,保证产品质量,轻量级产品可以提供规范清晰的源代码,有业务 ...

  8. java 并发性和多线程 -- 读感 (一 线程的基本概念部分)

    1.目录略览      线程的基本概念:介绍线程的优点,代价,并发编程的模型.如何创建运行java 线程.      线程间通讯的机制:竞态条件与临界区,线程安全和共享资源与不可变性.java内存模型 ...

  9. windows 8.1 试用感受:蛋疼感大幅降低

    众所周知windows 8 的最大使用感受就是蛋疼. 无论是微软MVP,还是我这样的万年不悔微软小白鼠,普通用户,小白用户,或多或少的都对这款操作系统感到蛋疼. 槽点太多,以至于大家都懒得批判了.好在 ...

随机推荐

  1. [工具类]DataTable与泛型集合List互转

    写在前面 工作中经常遇到datatable与list,对于datatable而言操作起来不太方便.所以有的时候还是非常希望通过泛型集合来进行操作的.所以这里就封装了一个扩展类.也方便使用. 类 方法中 ...

  2. [C#基础]说说lock到底锁谁?

    写在前面 最近一个月一直在弄文件传输组件,其中用到多线程的技术,但有的地方确实需要只能有一个线程来操作,如何才能保证只有一个线程呢?首先想到的就是锁的概念,最近在我们项目组中听的最多的也是锁谁,如何锁 ...

  3. linux用终端上传文件和文件家到远程的服务器

    文件上传:scp 本地文件地址 root@aifei8.net:/var/www/html/landrover 文件夹上传:1.先进入文件夹目录 2. 执行命令:scp -r . root@aifei ...

  4. linux oracle磁盘满了

    最近,查看我们一台linux服务器,发现硬盘空间都已经使用了95%,很是疑惑啊,怎么回事那?难道是数据库文件太大了? Filesystem            Size  Used Avail Us ...

  5. .net架构设计读书笔记--第三章 第9节 域模型实现(ImplementingDomain Model)

        我们长时间争论什么方案是实现域业务领域层架构的最佳方法.最后,我们用一个在线商店案例来说明,其中忽略了许多之前遇到的一些场景.在线商店对很多人来说更容易理解. 一.在线商店项目简介 1. 用例 ...

  6. Hive简单优化;workflow调试

    1. 定义job名字 SET mapred.job.name='customer_rfm_analysis_L1'; 这样在job任务列表里可以第一眼找到自己的任务. 2. 少用distinct, 尽 ...

  7. javax/faces/webapp/FacesServlet

    严重: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component ...

  8. .net mvc4 利用 kindeditor 上传本地图片

    http://blog.csdn.net/ycwol/article/details/41824371?utm_source=tuicool&utm_medium=referral 最近在用k ...

  9. 软件开发过程中的审查 (Review)

    http://blog.csdn.net/horkychen/article/details/5035769 软件开发过程中的审查 (Review)   希望别人做些什么->定义出流程 希望别人 ...

  10. ExtJS入门教程03,form中怎能没有validation

    接上篇内容,我们在学会extjs form的基本用法之后,今天我们来看看extjs form的validation功能. 必填项,就是不能为空(allowBlank) 效果: 代码: { xtype: ...