The Suspects POJ 1611
The Suspects
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
题意: 0号必然感染,和0号一组的是感染者,还有这一组中的去其他人也会去感染其他人,然后问你最多有多少感染者
题解:有一个技巧就是初始化是t[i]=1;在mix()函数中相加。需要注意此题最少有一个人。
#include<stdio.h>
int road[10000000+10];
int t[10000000+10];
int find(int a)
{
    if(road[a]==a) return a;
    else
    return road[a]=find(road[a]);
}
void mix(int a,int b)
{
    int x;
    int y;
    x=find(a);
    y=find(b);
    if(x!=y)
    {
        road[y]=x;
        t[x]+=t[y];//是两个集合连接在一起,并使人数相加
    }
}
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    if(n==0&&m==0)
    {
        break;
    }
    else
    {
        int a, b,c,maxx=0;
        for(int i=0;i<=n;i++)
        {
            road[i]=i;
            t[i]=1;
        }
        while(m--)
        {
            scanf("%d",&a);
            scanf("%d",&b);
            for(int i=0;i<a-1;i++)
            {
                scanf("%d",&c);
                mix(c,b);
            }
        }
        int MAX=0;
        MAX=t[find(0)];
        printf("%d\n",MAX);
    }
    return 0;
}The Suspects POJ 1611的更多相关文章
- (并查集)The Suspects --POJ --1611
		链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ... 
- C - The Suspects POJ - 1611(并查集)
		Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ... 
- B - The Suspects -poj 1611
		病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ... 
- 【原创】poj -----  1611 The Suspects 解题报告
		题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ... 
- poj 1611 The Suspects 解题报告
		题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ... 
- poj 1611 The Suspects(简单并查集)
		题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ... 
- POJ - 1611 The Suspects  【并查集】
		题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ... 
- 【裸的并查集】POJ 1611 The Suspects
		http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ... 
- 并查集   (poj 1611 The Suspects)
		原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ... 
随机推荐
- postgresql安装,java简单使用postgresql
			一 整合 由于本人的学过的技术太多太乱了,于是决定一个一个的整合到一个springboot项目里面. 附上自己的github项目地址 https://github.com/247292980/spri ... 
- UiPath Studio 快捷键
			掌握快捷键可以事半功倍,写一下比较重要的 1. Ctrl + J 插入代码片段 2. Ctrl + K 快速建变量 3. Ctrl + L 打开日志文件夹 4. Ctrl + F4 关闭当前机 ... 
- MS Chart 折线图——去除时间中的时、分、秒,按天统计【转】
			MS Chart 折线图——去除时间中的时.分.秒,按天统计 private void Form2_Load(object sender, EventArgs e){ str ... 
- 《C#高效编程》读书笔记08-推荐使用查询语法而不是循环
			C#语言中并不缺少控制程序流程的结构,for.while.do/while和foreach等都可以做到这一点.但我们还有更好的方式:查询语法(query syntax) 下面这段代码演示了用命令式的方 ... 
- java-jsch实现sftp文件操作
			(曾在天涯)的文章详细讲解了jsch中的函数以及用法 http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html http://www. ... 
- FreeMarker基本语法的使用
			参考博客: http://www.cnblogs.com/panchanggui/p/9346574.html https://blog.csdn.net/zyy88886666/article/de ... 
- iOS .Crash文件分析处理办法 (利用symbolicatecrash工具处理)
			崩溃分析方式:命令行解析Crash文件 通过Mac自带的命令行工具解析Crash文件需要具备三个文件 symbolicatecrash,Xcode自带的崩溃分析工具,使用这个工具可以更精确的定位崩溃所 ... 
- 自己实现的简单的grid
			12年在第一家公司的时候,有过很长一段时间在前端的使用研究上.一开始的时候使用ExtJs4.0 MVC 来开发前端,觉得里面的风转的组件非常好用,Panel.window.tree等等,简化了对于前端 ... 
- CSS变量(CSS variable)
			使用 CSS 变量编写你的样式代码 基本使用: 1. --variable: <declaration-value> 2. <css-attribute>: var(--var ... 
- 利用临时表实现CTE递归查询
			一.CTE递归查询简介 --CTE递归查询终止条件在TSQL脚本中,也能实现递归查询,SQL Server提供CTE(Common Table Expression),只需要编写少量的代码,就能实现递 ... 
