博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[kuangbin带你飞]专题五 并查集 B - The Suspects
阅读量:4557 次
发布时间:2019-06-08

本文共 2549 字,大约阅读时间需要 8 分钟。

B - 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 42 1 25 10 13 11 12 142 0 12 99 2200 21 55 1 2 3 4 51 00 0
Sample Output
411 题意:0号是病毒感染者,与0在一组的都被感染了,共有编号为1~n的n个人,m组,给出m组的每组人的编号,求被感染的人有多少 思路:只要求每个人的头是不是0就行辽,是就加1
//// Created by hanyu on 2019/7/23.//#include 
#include
#include
#include
using namespace std;const int maxn=3e4+10;int father[maxn],res[maxn];struct Node{ int x; int y;}node[maxn];int find(int x){ if(x==father[x]) return x; return father[x]=find(father[x]);}void merge(int x,int y){ int xx=find(x); int yy=find(y); if(xx!=yy) father[xx]=yy;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; for(int i=0;i

 

 

转载于:https://www.cnblogs.com/Vampire6/p/11233733.html

你可能感兴趣的文章
对我影响最深的三个老师
查看>>
开源项目托管GitHub
查看>>
Unity学习笔记—— 常用脚本函数
查看>>
.getCellType()的几种类型值
查看>>
linux中启动 java -jar 后台运行程序
查看>>
运行web项目端口占用问题
查看>>
Java Spring-IOC和DI
查看>>
【NOIP1999】【Luogu1015】回文数(高精度,模拟)
查看>>
Linux上安装Python3.5
查看>>
crt安装
查看>>
git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git
查看>>
c++中static的用法详解
查看>>
转 我修改的注册表,但是程序运行起来,还是记着以前的
查看>>
图片轮播功能
查看>>
第六周小组作业:软件测试和评估
查看>>
linux Cacti监控服务器搭建
查看>>
debian(kali Linux) 安装net Core
查看>>
centos 7防火墙设置
查看>>
自定义进度条(圆形、横向进度条)
查看>>
spark-streaming-kafka采坑
查看>>