http://poj.org/problem?id=1611

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

0号患了病毒,只要和0号一组的人同样会患病毒。。。。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int bin[];
int q[];
int n,m;
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int findx(int x)
{
int r,j,k;
r=x;
while(bin[r]!=r)
r=bin[r];
k=x;
while(k!=r)
{
j=bin[k];
bin[k]=r;
k=j; }
return r;
}
void merge(int x,int y)
{
int fx,fy;
fx=findx(x);
fy=findx(y);
if(fx!=fy)
{
bin[fx]=fy;
}
} int main()
{
int n,x,t,i,j;
while(scanf("%d%d",&n,&x)!=EOF)
{
if(n==&&x==) break;
for(i=; i<n; i++)
bin[i]=i;
while(x--)
{
scanf("%d",&t);
memset(q,,sizeof(q));
for(j=; j<t; j++)
scanf("%d",&q[j]);
qsort(q,t,sizeof(q[]),cmp);
for(j=; j<t; j++)
{
merge(q[j],q[j-]);
} }
/*for(i=0;i<n;i++)
printf("...%d",bin[i]);*/
int l=;
for(i=; i<n; i++)
{
if(findx(i)==findx())
l++; }
printf("%d\n",l); }
return ;
}

POJ1611:The Suspects(模板题)的更多相关文章

  1. POJ1611 The Suspects 并查集模板题

    题目大意:中文题不多说了 题目思路:将每一个可能患病的人纳入同一个集合,然后遍历查找每个点,如果改点点的根节点和0号学生的根节点相同,则该点可能是病人. 模板题并没有思路上的困难,只不过在遍历时需要额 ...

  2. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  3. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  4. POJ2774 & 后缀数组模板题

    题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...

  5. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  6. HDU-3549 最大流模板题

    1.HDU-3549   Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...

  7. HDU 4280:Island Transport(ISAP模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...

  8. HDU-2222 Keywords Search(AC自动机--模板题)

    题目大意:统计一共出现了多少次模板串. 题目分析:AC自动机的模板题.不过这题有坑,相同的模板串不能只算一次. 代码如下: # include<iostream> # include< ...

  9. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  10. AC自动机 - 多模式串匹配问题的基本运用 + 模板题 --- HDU 2222

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. day_4_25 py

    ''' 递归: 如果一个函数在内部不调用其它的函数, 而是自己本身的话,这个函数就是递归函数 ''' def factor(num): if num >1: result = num*facto ...

  2. Ingeter与int的比较

    ,Ingeter是int的包装类,int的初值为0,Ingeter的初值为null.但是如果面试官再问一下Integer i = 1;int ii = 1; i==ii为true还是为false? 首 ...

  3. Flask web开发之路一

    之前学过一段时间的flask,感觉还是挺好用的,自己的专利挖掘项目也想这个web框架来搭建,于是重新开始基础学习 环境:win10,python3.6,pycharm2017,虚拟环境virtuale ...

  4. novnc安装教程

    适配于centos7 1.安装vncserver # stop selinux and iptables setenforce systemctl stop firewalld systemctl d ...

  5. [No000013A]Windows WMIC命令使用详解(附实例)

    第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符.在WMIC命令行提示符上,命令以交互的方式执行 执行“wmic”命令启动WMIC命令行环境.这个命令可以在 ...

  6. 【魔改】hdu6325 多校赛3G xy排序凸包+llvector模板

    凸包算法前的预处理,可以极角排序,也可以按X,Y轴排序, 极角排序需要找到角落里的一个点,Xy轴排序要跑两遍凸包 而本题的要求只要一个上半凸包,并且有X轴从小到大以及字典序限制,完全符合xy排序,直接 ...

  7. maven工程之pom模板(hadoop、hive、hbase)

    以下配置文件涵盖了hadoop.hive.hbase开发支持库的配置. 仅需针对maven工程pom.xml文件做相应更改就可以自动生成hadoop开发支持库. <properties>  ...

  8. webstorm 智能提示忽略大小写

    setting-Editor-General-Code Completion里的 Case sensitive completion: 可以设置只第一个字母敏感.完全敏感或者不敏感. 选择none.. ...

  9. ACM:油田(Oil Deposits,UVa 572)

    /* Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  10. html select控件的jq操作

    html select控件的jq操作 1.判断select选项中 是否存在Value="paraValue"的Item $("#selectid option[@valu ...