A - The Suspects (sars传染)
题意:有m组,0为起点,有0的那一组全是嫌疑人,之后会不断传递到其它组去,问一共有多少人是嫌疑人。
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<math.h>
#include<stdlib.h>
#include<functional>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
int n,m,pre[30005],a[30005];
int find(int x)
{
return x==pre[x]?x:pre[x]=find(pre[x]);
}
void merge(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
pre[fx]=fy;
}
int main()
{
while(cin>>n>>m&&(n+m))
{
for(int i=0;i<n;i++)//每人一个父节点
pre[i]=i;
for(int i=0;i<m;i++)
{
int k;
cin>>k;
cin>>a[0];
for(int j=1;j<k;j++)
{
cin>>a[j];
merge(a[0],a[j]);
//因为每一行都是有关系的,
//将每一行关联起来。
}
}
int ans=0;
for(int i=0;i<n;i++)
{
if(find(i)==pre[0])//判断0和第i个人是否有关系
ans++;
}
printf("%d\n",ans);
}
}
A - The Suspects (sars传染)的更多相关文章
- 并查集模板题(The Suspects )HZNU寒假集训
The Suspects Time Limit: 1000MS Memory Limit: 20000KTotal Submissions: 36817 Accepted: 17860 Descrip ...
- The Suspects——Asia Kaohsiung 2003
原创 The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 48698 Accepted: 23286 Des ...
- POJ——1611The Suspects(启发式并查集+邻接表)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 31100 Accepted: 15110 Descri ...
- 并查集 (Union Find ) P - The Suspects
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
- poj-1611-The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 34284 Accepted: 16642 De ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
- Poj1611The Suspects
A - The Suspects Time Limit: 1000 MS Memory Limit: 20000 KB 64-bit integer IO format: %I64d , %I64u ...
- poj 1611 The Suspects 并查集
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 30522 Accepted: 14836 De ...
随机推荐
- 在Windows中安装MongoDB--图文并茂
在Windows环境下安装MongoDB的方法 (1)下载MongoDB Windows版: 进入MongoDB官网 (2)设置数据文件和日志文件的存放目录: 打开刚刚安装MongoDB的目录咋bin ...
- 【Oracle】Oracle SQL的优化软件
对于SQL开发人员和DBA来说,根据业务需求写出一条正确的SQL很容易.但是SQL的执行性能怎么样呢?能优化一下跑得更快吗?如果不是资深 DBA,估计很多人都没有信心. 幸运的是,自动化优化工具可以 ...
- WPF NET5 Prism8.0的升级指南
前言 曾经我以学习的目的写了关于在.NET Core3.1使用Prism的系列文章.NET Core 3 WPF MVVM框架 Prism系列文章索引,也谢谢大家的支持,事实上当初的版本则是Pri ...
- WCNSS_qcom_cfg.ini WIFI配置文件参数详细解析
STA相关的一般配置 参数 含义 最小值 最大值 默认值 gNeighborLookupThreshold 1 触发roam scan发生的条件在WCNSS_qcom_cfg.ini文件中gNeigh ...
- .NET 项目中的单元测试
.NET 项目中的单元测试 Intro "不会写单元测试的程序员不是合格的程序员,不写单元测试的程序员不是优秀的工程师." -- 一只想要成为一个优秀程序员的渣逼程序猿. 那么问题 ...
- 1.8V转3V,1,8V转3.3V电源芯片的规格书参数
1.8V电平如何稳压稳定输出3V或者3.3V,就需要用到1.8V转3V,1,8V转3.3V电源芯片,就PW5100(低功耗,外围简单),PW5200A是可调输出电压,可以输出电压根据外围电阻来设置命令 ...
- 飞机大战(1)--添加logo和加载动画
注:以下代码都是用scratch 3.0版本编写 素材链接: 链接:https://pan.baidu.com/s/1sXqeZVuFgVTYT0OtqxXilw 提取码:1126 一.背景添加 导入 ...
- 使用Gulp里面的浏览器同步插件browser-sync的注意事项
使用Gulp里面的浏览器同步插件browser-sync的注意事项 第一步:打开你的开发者工具, 编写前端代码!图如下! 第二步:打开你当前工作目录的命令行窗口 第三步:输入浏览器同步执行的代码! b ...
- CSGO项目
#include <Windows.h> #include <sstream> #include <iostream> #include <math.h> ...
- (Oracle)误删oracle表结构恢复
在操作数据库时,我们常常会不小心把表结构删除了.有时候建表很麻烦大到100多个字段,而又找不到当初的建表语句.其实这时候不用担心,oracle和咱们widows一样,他也有个回收站,只要你没有清除回收 ...