POJ1161——The Suspects
POJ1161——The Suspects
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 48220 | Accepted: 23072 | 
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
#include<iostream>
#include<cstdio>
#define N 4000000
#define LL long long
#define RE register
#define IN inline using namespace std; IN void in(int &x) {
RE char c=getchar();x=;int f=;
while(!isdigit(c)) {if(c=='-') f=-;c=getchar();}
while(isdigit(c)) {x=x*+c-'';c=getchar();}
x*=f;
} int n,m,fa[N],w[N],anss,ans; int find(int x){return fa[x]==x?x:find(fa[x]);} int main()
{
while(){
in(n);in(m);
if(n==&&m==) return ;
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
int tp;
in(tp);
for(int j=;j<=tp;j++){
int fx,fy;in(w[j]);
fx=find(w[j]);
for(int k=;k<j;k++){
fy=find(w[k]);
if(fx!=fy) fa[fx]=fy;
}
}
}ans=find();anss=;
for(int i=;i<=n;i++){
if(find(i)==ans) ++anss;
}printf("%d\n",anss);
}return ;
}
POJ1161——The Suspects的更多相关文章
- [并查集] 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 ... 
- DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
		题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ... 
- 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 ... 
- LA  4126 Password Suspects
		问题描述:给定m个模式串,计数包含所有模式串且长度为n的字符串的数目. 数据范围:模式串长度不超过10,m <= 10, n <= 25,此外保证答案不超过1015. 分析:既然要计数给定 ... 
- POJ 1611  The Suspects (并查集)
		The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ... 
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
		B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ... 
随机推荐
- 5分钟Serverless实践 | 构建无服务器图片鉴黄Web应用
			Serverless是什么 Serverless中文译为“无服务器”,最早可以追溯到2012年Ken Fromm发表的<Why The Future Of Software And Apps I ... 
- struts2 一个CRUD的BaseAction
			在struts2 in action中所见,这样封装后省去了大部分crud反复代码.尽管还不能理悟.先记下来. abstract class BaseAction extends ActionSupp ... 
- Elasticsearch安装中文分词插件ik
			Elasticsearch默认提供的分词器,会把每一个汉字分开,而不是我们想要的依据关键词来分词.比如: curl -XPOST "http://localhost:9200/userinf ... 
- 【转】Java - printf
			[转自]http://heidian.iteye.com/blog/404632 目前printf支持以下格式: %c 单个字符 %d ... 
- E20170807-mk
			literal adj. 照字面的; 原义的; 逐字的; 平实的,避免夸张; 
- Magnetic Storms
			http://acm.timus.ru/problem.aspx?space=1&num=1126 简单的线段树求区间最值 #include <stdio.h> #include ... 
- 让谷歌浏览器(chrome)保存调试代码workspace
			方法/步骤 chrome浏览器早期版本的操作方法与我现在要讲的方法有所不同,因此操作前请注意浏览器的版本号. 示例中的版本号: 53.0.2785.116 m 任意打开一个需要调试的html文件 ... 
- Android点9图的运用
			在Android UI设计开发中,我们经常会用到一些图标.图片来做背景等. 相信很多同学都会遇到一个问题,就是我们让美工做好一张图,一个图标,呃,看起来挺好看的,但是放进app中,扩大或缩小.在不同分 ... 
- Android 签名(5)用命令签名和用android studio,eclipse签名
			1,用命令签名 无论用哪个 IDE 开发,最终只是用了 keytool 和 jarsigner 这两个 Java 工具来完成签名任务(在 jdk 的 bin 目录下).其中 keytool 用来生成 ... 
- RabbitMQ~消息的产生和管理(15672)
			上一讲说了rabbitmq在windows环境的部署,而今天主要说一下消息在产生后,如何去查看消息,事实上,rabbitmq为我们提供了功能强大的管理插件,我们只要开启这个插件即可,它也是一个网站,端 ... 
