POJ1611(KB2-B)
The Suspects
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 39211 | Accepted: 18981 |
Description
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
Source
//2017-07-19
#include <iostream> using namespace std; const int N = ;
int n, m, fa[N]; void init(){
for(int i = ; i < N; i++)
fa[i] = i;
} int getfa(int x){
if(x == fa[x])return x;
else return fa[x] = getfa(fa[x]);
} void merge0(int a, int b){
int af = getfa(a);
int bf = getfa(b);
if(af != bf)
fa[bf] = af;
} int main(){
while(cin>>n>>m){
if(!n && !m)break;
init();
int k, a, b;
while(m--){
cin>>k>>a;
for(int i = ; i < k-; i++){
cin>>b;
merge0(a, b);
}
}
int ans = ;
for(int i = ; i < n; i++){
if(getfa(i) == fa[])
ans++;
}
cout<<ans<<endl;
} return ;
}
POJ1611(KB2-B)的更多相关文章
- 并查集 poj1611&poj2492
poj1611 简单题 代码中id记录父节点,sz记录子树规模.一个集合为一棵树. #include <iostream> #include <cstdio> using na ...
- poj1611 The Suspects(并查集)
题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...
- poj1611(并查集)
题目链接:http://poj.org/problem?id=1611 题意: SARS(非典型肺炎)传播得非常厉害,其中最有效的办法是隔离那些患病.和患病者接触的人.现在有几个学习小组,每小组有几个 ...
- poj1611 并查集 (路径不压缩)
http://poj.org/problem?id=1611 题目大意: 有一个学校,有N个学生,编号为0-N-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染,并且这些人如果还参加了别的社 ...
- poj1611(感染病患者)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24587 Accepted: 12046 De ...
- poj1611 带权并查集
题意:病毒蔓延,现在有 n 个人,其中 0 号被认为可能感染,然后给出多个社交圈,如果某个社交圈里有人被认为可能被感染,那么所有这个社交圈里的人都被认为可能被感染,现在问有多少人可能被感染. 带权并查 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- poj1611 并查集
题目链接:http://poj.org/problem?id=1611 #include <cstdio> #include <cmath> #include <algo ...
- poj1611 简单并查集
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 32781 Accepted: 15902 De ...
随机推荐
- Tomcat在Linux下的安装
按部就班的把 tomcat 上传到 Linux 我创建了一个文件夹用作存放解压文件 ( tomcat只要解压就可以使用 ) 解压 : tar -xvf apache-tomcat-7.0.52.t ...
- 【文档】使用Sphinx + reST编写文档
0 前言 写文档是开发人员日常工作中的一项重要内容,除了word之外,我更偏爱使用标记语言(Markup Language).使用标记语言,可以利用简单.免费的文本编辑器(记事本,vim, emacs ...
- linux系统坏了,进不了登陆界面怎么办?
装oracle时,命令弄错了,结果系统崩溃之后就进不去系统了,启动后光标一直在闪烁,就是不显示登陆界面. 网上查了很多,什么grub引导之类的,完全没办法恢复系统. 系统坏了倒是无所谓,主要是系统上还 ...
- cmd命令关闭占用程序的端口
遇到的问题: 在重新启动tomcat服务时,启动失败,显示的信息大概为:Error running 'cus_manager_system': Unable to open debugger port ...
- 在vue里面使用iVew框架
iVew框架的文档 https://www.iviewui.com/docs/guide/install 这里使用的是 npm 来安装,在项目下执行下面命令npm install iview -- ...
- defer 的常用场景
将panic的转化为error类型值,并将其作为函数值返回给调用方 package main import "fmt" func divide(a, b int) (res int ...
- 读取excel合并单元格内容
def get_excel_content(excel_path): contents = [] if self.log_path.endswith('xls'): workbook = xlrd.o ...
- vs 2017 IIS EXPRESS 增加局域网访问
在VS调试站点,默认使用IISExpress,locall+端口,为了使用IP地址.多域名调试,找到 IISExpress下的applicationhost.config,在目标站点下增加类似行: & ...
- ASP.NET Core 中使用 GrayLog 记录日志
使用 UDP 协议发送日志 自定义好的查询 key 存储数据,尽量不要使用 graylog2-server 服务端格式化日志再存储 Ubuntu 安装服务端 sudo apt-get update & ...
- Elasticsearch5.3.1 IK分词,同义词/联想搜索设置
[大数据]-Elasticsearch5.3.1 IK分词,同义词/联想搜索设置 原文地址:http://www.cnblogs.com/NextNight/p/6837407.html --题外话 ...