(并查集)The Suspects --POJ --1611
链接:
http://poj.org/problem?id=1611
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/B
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 30005 int a[N];
int n, m; int Find(int x)
{
if(a[x]!=x)
a[x] = Find(a[x]);
return a[x];
} int main()
{ while(scanf("%d%d", &n, &m), n+m)
{
int p, px, py, s, x, y; for(int i=; i<=n; i++)
a[i] = i; for(int i=; i<m; i++)
{
scanf("%d%d", &s, &x); for(int j=; j<s; j++)
{
scanf("%d", &y); px = Find(x);
py = Find(y);
if(px!=py)
a[py] = px;
}
}
int sum=;
p = Find(); for(int i=; i<n; i++)
if(Find(i)==p)
sum++; printf("%d\n", sum); }
return ;
}
(并查集)The Suspects --POJ --1611的更多相关文章
- C - The Suspects POJ - 1611(并查集)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- B - The Suspects -poj 1611
病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ...
- The Suspects POJ 1611
The Suspects Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, w ...
- 并查集判树 poj 1308
例题: poj 1308 题目大意比较简单,对任意两个点,有且仅有一条道路,也就是一棵树. 题解:一棵树中,肯定是不能有环的,而且只能由一个根节点.(没认真读题,只知道在那里判环....),所以这个题 ...
- kuangbin 并查集
A : Wireless Network POJ - 2236 题意:并查集,可以有查询和修复操作 题解:并查集 #include<iostream> #include<cstdi ...
- [kuangbin带你飞]专题五 并查集
并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...
- 并查集 (poj 1611 The Suspects)
原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...
- [并查集] 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: 21472 Accepted: 10393 De ...
随机推荐
- adb设置逍遥游
. adb设置模拟器属性imei.imsi.手机号.sim卡号2. adb设置充电模式3. 开启|关闭飞行模式4. 获取所有已安装程序apk路径和包名5. adb对指定设备执行指令6. 安装应用7. ...
- Mysql 多个字段查找重复数
delete FROM `test_table` WHERE id in (SELECT id,concat(user_id,user_id2) as __fFROM `test_table` whe ...
- PR合并回写
) as LGORT ,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so_id,out_pr.so_lineid,out_pr.sobsl from V_ ...
- Redis事务的简单理解
Redis事务的命令如下所示: 先以 MULTI 开始一个事务, 然后将多个命令入队到事务中, 最后由 EXEC 命令触发事务, 一并执行事务中的所有命令 示例如下: //开始一个事务 > MU ...
- jquery获取input file的文件名,具有兼容性
var str=$(this).val();var arr=str.split('\\');//注split可以用字符或字符串分割var fileName=arr[arr.length-1];//这就 ...
- joinablequeue模块 生产者消费者模型 Manager模块 进程池 管道
一.生产者消费者 主要是为解耦(借助队列来实现生产者消费者模型) import queue # 不能进行多进程之间的数据传输 (1)from multiprocessing import Queue ...
- 84. Largest Rectangle in Histogram (Array, Stack; DP)
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- 53. Maximum Subarray最大求和子数组12 3(dp)
[抄题]: Find the contiguous subarray within an array (containing at least one number) which has the la ...