C - The Suspects
2019冠状病毒病(英语:Coronavirus disease 2019,缩写:COVID-19 ),是一种由严重急性呼吸系统综合症冠状病毒2型(缩写:SARS-CoV-2)引发的传染病。此病在全球各国大规模爆发并急速扩散,成为人类历史上致死人数最多的流行病之一。 很显然,目前最好的办法就是将所有可能的患者都隔离起来。 现在某高校正在排查可能的患者,这个高校中有多个社团,每个社团经常进行内部交流,一名学生可能会加入多个社团。学校认为一旦某个社团里出现一名可疑患者,这整个社团的学生都被视为是可能的患者。 现在请你帮忙找到这所学校的所有可能的患者。
Input
输入文件包含多组数据。
对于每组测试数据:
第一行为两个整数n和m, 其中n是学生的数量, m是社团的数量。0 < n <= 30000,0 <= m <= 500。
接下来m行,每一行有一个整数k,代表社团中学生的数量。之后,有k个整数代表这个社团里每个学生的编号(在0到n-1之间)。
n = m = 0表示输入结束,不需要处理。
Output
对于每组测试数据, 输出可能的患者数目。
Sample Input
100 4 2 1 2 6 11 13 50 12 14 2 0 1 2 99 2 200 2 1 5 6 5 6 7 8 9 10 1 0 0 0
Sample Output
4 1 1
简单并查集水题,wlb都会的!直接拿捏住!
上代码!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 31000
int father[MAXN],rank[MAXN];void Init(int n)
{int i;for(i=0;i<n;i++){father[i]=i;rank[i]=1;}
}int Find_Set(int x)
{if(x!=father[x]){father[x]=Find_Set(father[x]);}return father[x];
}void Union(int x,int y)
{x=Find_Set(x);y=Find_Set(y);if(x==y)return;if(rank[x]>=rank[y]){father[y]=x;rank[x]=rank[x]+rank[y];}else{father[x]=y;rank[y]=rank[y]+rank[x];}
}int main()
{ios::sync_with_stdio(false);int n,m,k,first,next;int i,j;while(1){cin>>n>>m;if(n==0 && m==0)break;Init(n);for(i=0;i<m;i++){cin>>k>>first;for(j=1;j<k;j++){cin>>next;Union(first,next);}}cout<<rank[father[0]]<<endl;}return 0;
}
C - The Suspects相关推荐
- B - The Suspects POJ - 1611
B - The Suspects POJ - 1611 基并查集 #include<iostream> #include<cstdio> #include<cstring ...
- POJ 1611 -The Suspects (并查集)
题目 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, ...
- The Suspects//并查集
题目: The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 48312 Accepted: 2311 ...
- Poj 1611 The Suspects
Poj 1611 的传送门 ***The Suspects*** Description Severe acute respiratory syndrome (SARS), an atypical p ...
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- (并查集)The Suspects
题目 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recogni ...
- B - The Suspects(并查集)详解
题目描述:n个学生分属m个团体,一个学生可以属于多个团体.一个学生疑似患病则它所属的整个团体都疑似患病.已知0号学生疑似患病,以及每个团体都由哪些学生构成,求一共多少个学生疑似患病. 解题思路:本题的 ...
- UVALive 4126 Password Suspects(AC自动机+dp)
题意就是长度为n的串,满足下列m个串是它的子串,问这个串有多少种,如果少于42种则字典序输出. dp[i][j][k]为,填充了i个字符,在ac自动机的j节点上,字串集合为k的方案数,填充i个字符可以 ...
- OJ:The Suspects(C++)
描述 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recogni ...
- UVALive 4126 (LA 4126) Password Suspects AC自动机 + DP + 剪枝dfs
题目大意: 白书练习题 就是给了M(0 <= M <= 10)个长度不超过10的串, 现在问长度为N(N <= 25)的包含所有这M个串作为子串的串有多少种 如果种数<=42按 ...
最新文章
- 《中国人工智能学会通讯》——1.42 理解情感
- SQL语法之排序查询(进阶3)and常见函数(进阶4)
- 关于继承构造器的调用
- 光端机的使用注意事项详解
- android使用 注解框架,Android实践 | 注解框架ButterKnife基本使用
- VSCode每打开一次文件弹出一个git弹窗:-login -i rev-parse --show-toplevel
- php主页修改软件,程序安装后依然是老版主页的修改办法
- python载入图片序列_python – 使用matplotlib显示图像序列
- 最新计算机主板参数,电脑主板参数知识
- 【KnockoutJS】KnockoutJS 绑定列表数据。实现表头合并,列生成,图片上传等功能
- 我的大学四年到毕业工作5年的学习路线资源汇总
- deepin安装教程(deepin安装教程不用u盘)
- 图片转Excel表格
- 自主导航系列21-layered论文阅读
- Python办公——根据Excel数据批量生成二维码
- brew upgrade出现It seems there is already an App at的解决方法
- 订单信息表和订单明细表
- 设置无线路由器与有线网络在同一网段
- macbook pro window蓝牙驱动 下载
- js实现仿微信红包随机分配