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 ...
随机推荐
- bzoj 1022 小约翰的游戏John
题目大意: n堆石子,两个人轮流取石子,每个人取的时候,可以随意选择一堆石子 在这堆石子中取走任意多的石子,但不能一粒石子也不取,取到最后一粒石子的人算输 思路: 首先当每堆石子数都为1时,偶数为先手 ...
- [SCOI 2010] 连续攻击游戏
[题目链接] https://www.luogu.org/problemnew/show/P1640 [算法] 二分图匹配 实现时需要常数优化和特判 [代码] //code by byf and lm ...
- 杂项-JSP-Runoob:JSP 标准标签库(JSTL)
ylbtech-杂项-JSP-Runoob:JSP 标准标签库(JSTL) 1.返回顶部 1. JSP 标准标签库(JSTL) JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通 ...
- mariadb的安装
mysql (分支 mariadb)1.安装mariadb -yum -源码编译安装 -下载rpm安装 yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./co ...
- ACM_Jack拆炸弹(深搜)
Jack拆炸弹 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个由n*n个格子组成的监狱里被恐怖份子安置了一个定时炸弹.其中 ...
- Zabbix Server参数文件详解
Zabbix的配置文件一般有三种: zabbix_server.conf:zabbix server的配置文件 zabbix_proxy.conf:zabbix proxy的配置文件 zabbix_a ...
- scala的Map
package com.test.scala.test object MapTest { def main(args: Array[String]): Unit = { //定义一个不可变的map v ...
- Linq学习(三)-基本查询
一.本将主要介绍内容 从linq,sql,lambda三个角度比较来学习 select.orderby.分页.group by.distinct.子查询.in的用法 1.select 查询用户和它们的 ...
- Android项目实战_手机安全卫士进程管理
###1.设备进程信息获取获取设备运行进程 ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVI ...
- Appium Python API 汇总
最近在学习Python自动化,网络搜集而来,留着备用, 方便自己也方便他人.感谢总结的人! 1.contexts contexts(self): Returns the contexts within ...