poj 1611 dsu
Time Limit: 1000MS | Memory Limit: 20000K | |
Total Submissions: 35918 | Accepted: 17458 |
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 代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define pi acos(-1.0)
#define mj
#define inf 2e8+500
typedef long long ll;
using namespace std;
const int N=3e4+;
int p[N];
int find(int x)
{
return x==p[x]?x:p[x]=find(p[x]);
}
void unit(int x,int y)
{
x=find(x),y=find(y);
if(x==y) return ;
else p[x]=y;
}
int main()
{
int n,m,x,y;
while(scanf("%d%d",&n,&m)==,n||m){
for(int i=;i<n;i++){
p[i]=i;
}
int num;
for(int i=;i<m;i++){
scanf("%d%d",&num,&x);
num--;
while(num--){
scanf("%d",&y);
unit(x,y);
}
}
int ans=;
for(int i=;i<n;i++){
if(find()==find(i)) ans++;
}
printf("%d\n",ans);
}
return ;
}
poj 1611 dsu的更多相关文章
- poj 1611(并查集)
http://poj.org/problem?id=1611 题意:有个学生感染病毒了,只要是和这个学生接触过的人都会感染,而和这些被感染者接触的人,也会被感染,现在给定你一些协会的人数,以及所在学生 ...
- poj 1611 The Suspects 解题报告
题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...
- poj 1611 The Suspects(简单并查集)
题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- (并查集)The Suspects --POJ --1611
链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- POJ - 1611 The Suspects 【并查集】
题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...
- 【裸的并查集】POJ 1611 The Suspects
http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...
- 并查集 (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 ...
随机推荐
- HTML知识点梳理
- 微信小程序电商实战-商品详情(上)
先看一下今天要实现的小程序商品详情页吧! 商品详情.gif 本期我们要实现小程序商品详情页的头部标题.头部轮播.商品详情浮动按钮和商品内页布局. 一.设置头部标题 如上图所示,头部标题是商品详情 ...
- Swift中as as! as?的区别
as :类型一致或者子类 仅当一个值的类型在运行时(runtime)和as模式右边的指定类型一致 - 或者是该类型的子类 - 的情况下,才会匹配这个值.如果匹配成功,被匹配的值的类型被转换成as模 ...
- 一次ddos攻击
公司lvs的vip受到攻击,表现现象为: 1)vip所有服务器没有什么连接,大量的无效connection 2)网卡流量很大 停用vip,流量下降,临时解决攻击问题.但是这只是治标不治本,如果攻击方变 ...
- JS兼用IE8的通过class名获取CSS对象组
转自:Garon_InE 原生js方法“document.getElementsByClassName”在ie8及其以下浏览器中不能使用,所以写了一个兼容IE的方法. 完整的页面代码如下: testJ ...
- 笨办法学Python(十八)
习题 18: 命名.变量.代码.函数 标题包含的内容够多的吧?接下来我要教你“函数(function)”了!咚咚锵!说到函数,不一样的人会对它有不一样的理解和使用方法,不过我只会教你现在能用到的最简单 ...
- 正则表达式转换python2的print为python3风格
直接查找 print ([^\n\(]*)替换为 print($1)
- java 网络流 TCP/UDP
一.ServerSocket java.lang.Object |-java.net.ServerSocket 有子类SSLServerSocket. 此类实现服务器套接字.服务器套接字等待请求通过网 ...
- Fiddler-1 官网下载及安装
1 进入Fiddler官网:http://www.telerik.com/fiddler 点击[Free download]:填写一些信息后就可以下载. 2 双击安装包--下一步dinghanhua下 ...
- Android(java)学习笔记73:Intent启动Activity
1. Intent启动Activity案例 (1)首先是main.xml和other.xml文件如下: main.xml文件: <?xml version="1.0" enc ...