The Suspects

UVA - 1997:The Suspects UVA-1997:The Suspects 来源:UVA 标签:并查集 参考资料: 相似题目: 题目 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in m... 阅读详情

点击打开链接

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others. 
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
The input file contains several cases. Each test case begins with two integers n and m in a line, where n is the number of students, and m is the number of groups. You may assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 is recognized as a suspect in all the cases. This line is followed by m member lists of the groups, one line per group. Each line begins with an integer k by itself representing the number of members in the group. Following the number of members, there are k integers representing the students in this group. All the integers in a line are separated by at least one space. 
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.
Output
For each case, output the number of suspects in one line.
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

解析:只要是某组数据含有0,就让0作为根节点,然后记录数的节点数。


#include<stdio.h>
const int M=50000;
int par[M],vis[M];
int find(int x)
{
	return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx!=fy){
		if(fx==0){
			vis[0]+=vis[fy];
			par[fy]=fx;
		}
		else if(fy==0){
			vis[0]+=vis[fx];
			par[fx]=fy;
		}
		else{
			vis[fx]+=vis[fy];
		    par[fy]=fx;
		}
		
	}
}
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m)&&(n||m)){
		for(int i=0;i<=n;i++){
			par[i]=i;
			vis[i]=1;
		}
		int t,x,y;
		while(m--){
			scanf("%d",&t);
			scanf("%d",&x);
			for(int i=1;i<t;i++){
				scanf("%d",&y);
				unite(x,y);
			}
		}
		printf("%d\n",vis[0]);
	}
	
}


AlphaFold-multimer实战:从零开始预测STAT1-STAT2蛋白复合物结构 本文详细介绍了使用AlphaFold-multimer从零开始预测STAT1-STAT2蛋白复合物结构的完整实战流程。内容涵盖环境配置、数据库准备、序列处理、参数优化及结果可信度评估,为研究者利用这一AI工具进行复合物结构预测提供了系统指南和深度解析。 阅读详情

相关推荐

vivado2020.2安装教程:Windows平台完整指南

手把手带你完成vivado2020.2安装教程,覆盖下载、配置到验证全过程,解决常见安装问题,确保在Windows平台顺利部署开发环境,适合初学者快速上手。

weixin_42607969的博客 1347

*********(北大)并查集**********

目录 POJ 1703 Find them, Catch them // 种类并查集 自己的详细理解过程 回溯过程 POJ 1611 The Suspects POJ 1988 Cube Stacking POJ 1182 食物链   POJ 1703 Find them, Catch them // 种类并查集 自己的详细理解过程 回溯过程   POJ 1611 The Susp...

LMengi000的博客 391

制造业信息化的现实困局与未来展望:从基础到数字化的挑战与机遇

随着全球科技的发展和市场竞争的加剧,制造业的转型升级成为企业必须面临的挑战。在信息化和数字化的浪潮下,许多企业试图通过技术创新来提升自身竞争力。然而,现实情况是,绝大部分制造业企业的基本信息化都尚未完成,更遑论复杂的数字化。那么,制造业在信息化进程中面对哪些阻碍?未来又该如何实现从基础信息化到数字化的转型?

Yz2024的博客 2983

The Suspects (并查集(裸))

题目来源:https://vjudge.net/problem/POJ-1611 【题意】 给出n给点(0到n-1),m个阵营,其中0号是嫌疑犯,与他在同一阵营的都是嫌疑犯,并且一个人可能身在不同的阵营。问,嫌疑犯有多少人。 【思路】 既然与0号在同一阵营的人都是嫌疑犯,那么这些嫌疑犯如果在其他阵营,那么会惹得其他人也变成嫌疑犯,比如在一号阵营里有 2 4,二号阵营里有 1 2,那么

Crazy 450

AI大模型学习(14)AI 小白入门!用 OpenCV+Python 打造人体姿态识别系统,超详细教程来了

这篇教程介绍了如何使用Python+OpenCV+MediaPipe搭建入门级人体姿态识别系统。主要内容包括:人体姿态识别的应用场景(如健身APP、体感游戏)、开发环境搭建(安装Python、OpenCV和MediaPipe库)、核心代码实现(通过30行代码完成摄像头姿态检测),以及进阶功能开发(深蹲动作纠正算法和PPT体感控制器)。教程详细解析了MediaPipe的BlazePose模型架构和33个关键点的生理学意义,并提供了多线程优化等性能提升方案。该项目适合AI初学者实践,无需复杂算法即可实现实时人体

isoft888的专栏,致力于C#/python分享物联网、大数据,神经网络的等领域,欢迎讨论交流! 1555

POJ 1611 The Suspects

POJ 1611 The SuspectsDescription Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to

long-long-ago 465

游戏开发中的AI与RAG技术应用实践

检索增强生成(RAG)技术是当前AI领域的重要突破,它通过结合信息检索与文本生成能力,显著提升了大型语言模型在专业领域的实用性。其核心原理是建立动态知识库,在生成响应前先检索相关专业资料作为上下文。这种技术特别适合解决游戏开发中的复杂问题,如虚幻引擎API查询、角色背景生成等技术场景。在实际工程应用中,RAG系统需要精心设计分层检索策略、缓存机制和硬件加速方案。通过将RAG深度集成到游戏引擎工作流中,开发者可以快速解决技术难题,新成员也能更快掌握引擎特性,大幅提升团队协作效率。

weixin_29323977的博客 534

poj 1611 The Suspects

http://poj.org/problem?id=1611 The Suspects Time Limit:1000MS     Memory Limit:20000KB     64bit IO Format:%I64d & %I64u Submit Status Description Severe acute respiratory s

大太阳 476

Autosar MCAL-S32K324 Fee配置-基于EB

Autosar MCAL S32K324 Fee配置详解

赞的博客 1546

HFSS实战项目——高带外抑制特性SIW带通滤波器

本文对单级滤波器和双级滤波器的设计、工作原理及仿真结果进行了详细分析,并验证了双级SIW带通滤波器在性能方面的优越性,为微波通信系统中滤波器的设计和应用提供了重要参考。

2401_87464239的博客 1816

ZOJ 1789 The Suspects

ZOJ 1789 The Suspects(并查集) 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827365288 The Suspects Time Limit: 2000 msMemory Limit: 65536 KB Severe acute respiratory syndrome (SARS), an ...

weixin_43823753的博客 132

【FPGA教程案例89】编译码2——使用vivado核实现RS信道编译码

RS编码,又称里所码,即Reed-solomon codes,是一种前向纠错的信道编码,对由校正过采样数据所产生的多项式有效。当接收器正确的收到足够的点后,它就可以恢复原来的多项式,即使接收到的多项式上有很多点被噪声干扰失真。

FPGA/MATLAB学习教程/源码/项目合作开发 3545

POJ - 1611The Suspects-并查集

POJ - 1611 The Suspects Time Limit: 1000MS   Memory Limit: 20000KB   64bit IO Format: %I64d & %I64u Submit Status Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3

qq_18661257的专栏 1014

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

poj1611 The Suspects

poj1611 The Suspects 时空限制    1000ms/128MB Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To m...

H优快云 313

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

poj 1611 The Suspects(并查集)

题目链接:poj 1611 The Suspects 题目大意:学校有若干个社团,给出每个社团的成员,现在0号同学得了流感,问说至少应该隔离哪些人。 解题思路:并查集,开一个数组用于记录当前集合的人数,在合并两个集合的同时将人数相加,作为新集合的人数。 #include #include const int N = 30005; int n, m, f[N

不慌不忙、不急不躁 1057

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

POJ - 1611 The Suspects (并查集)

题目链接:http://poj.org/problem?id=1611点击打开链接 The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 39369   Accepted: 19056 Description Sever

xuejye的博客 290

The Suspects POJ - 1611 并查集

The Suspects POJ - 1611 知识点:并查集 我这里把查询和合并进行了优化,喜欢的话可以拿来当模板 在这里插入代码片#include<iostream> #include<algorithm> #define fori for(i=0;i<n;i++) #define fori1 for(i=1;i<=n;i++) #define ll lon...

ch_huibw的博客 145

poj union_find相关之1611 The Suspects

poj union-find 1611 The Suspects

ziqi9216的博客 295

POJ1161——The Suspects

POJ1161——The Suspects The Suspects Time Limit:1000MS Memory Limit:20000K Total Submissions:48220 Accepted:23072 Description Severe acute respiratory syndrome (S...

weixin_30443895的博客 120

【并查集-size[ ]】POJ 1611 The Suspects

POJ 1611 The Suspects #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <string> #inclu...

L_X_ 145

The Suspects POJ - 1611【并查集】

The Suspects POJ - 1611 题目 思路:并查集模板题,开一个cnt数组维护集合中点的数量,最后输出0号点所在集合中点的数量就可以了 具体代码如下 #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int N = 30010; int n, m; int p[N], cnt[N]; int group[N]; int find(int

qq_50702668的博客 142
上一篇: 素数环
下一篇: 畅通工程
☞十一
博客等级 码龄9年 8粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值