Poj1611 The Suspects 并查集基础题

Axure原型模板与元件库APP交互设计素材(附资料) 在Axure中,手机模型是展示APP或小程序界面效果的重要工具。通过导入手机模型元件,设计师可以更加直观地模拟真实设备的显示效果,从而更准确地评估设计的可行性和用户体验。Axure官方及第三方资源库中提供了多种品牌和型号的手机模型,如iPhone、Android等,设计师可以根据项目需求选择合适的模型进行使用。Axure作为一款强大的原型设计工具,为APP和小程序的设计与开发提供了丰富的界面组件元件库和交互设计素材。 阅读详情

Description

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

Source


并查集的最基本也是最重要,最核心的三个操作:找该元素所在集合的根节点、合并两个集合以及判断两个元素是否属于一个集合。


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 30000
int n,m;
int parent[maxn+10];
int total[maxn+10];
int getparent(int a)
{
    if(parent[a]!=a){
        parent[a]=getparent(parent[a]);
    }
    return parent[a];
}
void Merge(int a,int b)
{
    int p1=getparent(a);
    int p2=getparent(b);
    if(p1==p2){
        return;
    }
    total[p1]+=total[p2];
    parent[p2]=p1;
}
int main()
{
    while(~scanf("%d%d",&n,&m),n+m){
        for(int i=0;i<n;i++){
            parent[i]=i;
            total[i]=1;
        }
        for(int j=0;j<m;j++){
            int k,s,o;
            scanf("%d",&k);
            scanf("%d",&s);
            for(int i=1;i<k;i++){
                scanf("%d",&o);
                Merge(s,o);
            }
        }
        printf("%d\n",total[getparent(0)]);
    }
    return 0;
}


Spring Authorization Server自定义密码模式:突破标准OAuth2限制,实现MFA与复杂业务集成 OAuth 2.0授权框架是构建现代应用安全体系的基石,其密码模式(Resource Owner Password Credentials Grant)提供了一种直接的资源所有者凭证交换令牌的机制。该模式的核心原理是客户端收集用户密码并直接向授权服务器请求访问令牌,适用于受信任的客户端场景。在技术价值上,它简化了某些传统应用的OAuth集成流程。然而,标准实现往往难以满足复杂的现实业务需求,例如需要集成多因素认证(MFA)、对接外部LDAP目录服务或执行自定义密码加密校验等场景。Spring Authori 阅读详情

相关推荐

【GAMES101】现代计算机图形学入门 资料整理

课程网址 课程主页 包括ppt 课程PPT和视频 一篇搞定!GAMES101现代计算机图形学入门(全) 作业链接地址 作业论坛 GAMES101课程环境搭建(Win10+VSCode) 计算机图形学笔记 虎书pdf 提取:n2rx 【必须】:高等数学(微积分、线性代数)、算法、数据结构 【非必须】:信号处理、数值分析、大学物理(光学) 在线公式编辑器 一定要做作业,如果个人要配置环境的话应该是配置opencv,eigen这两个核心库就行了,目前觉得最核心的一个作业是作业3,实现着色器和渲染管线,做完一遍

ysh的博客 2684

并查集poj1611(隔离非典)

Description 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 str...

qq_40859951的博客 417

车载摄像头+max96712 + rk3568 调试过程中遇到的问题

本文主要讲述本人在调试rk3568通过mipi-csi2链接max967812,max96712再外接4路车载摄像头过程中遇到的问题,以及最终如何解决这些问题。图中会贴上很多重要且关键的波形图,以便读者在调试过程中进行比对,分析。 如果在调试过程中,mipi总线上的波形没得什么问题的话,还是抓图失败的情况下,需要着重检查 频率,lane数,摄像头分辨率,摄像头输入图像格式等重要配置。

Amelio Ming 2066

用并查集找出病源

例题是: poj-1611 这是一道关于疫情的题,非常适合出现在这个时候.... 原题是: Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimi...

SAP自学之路 480

uniapp原生安卓插件开发之路

声明: 我的功能需求:全局悬浮框,也就是在其他应用上依旧能悬浮。查遍uni文档,无法实现,甚至native.js也无法实现,无奈只能走上原生插件开发这条不归路了。(吐槽:天天写前端js,突然写了下android简直要炸,public static String啥的,var不香嘛,不过别人严谨肯定还是有别人道理的,加油吧,争取能入个门!) 本人不懂安卓开发,完全安卓小白,所以安卓方面可能表达的不是很好,安卓代码可能写的不优美,但我功能最终还是实现了。但是为了需求,能力总能被“逼”出来。有描述错误的还望指正

Jone's Area 1万+

第1关:STL模板之queue实例一:最少个数

头歌自创答案

xiyunSacire的博客 819

poj1611(感染病患者)

The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24587 Accepted: 12046 Description Severe acute respiratory syndrome (SARS), an atypical pneumoni...

weixin_30802273的博客 239

手把手教你用Alinx黑金开发板(Spartan-6)驱动ADF4351信号源(附Verilog SPI代码)

本文详细介绍了如何使用Alinx黑金开发板(Spartan-6 FPGA)驱动ADF4351信号源,包括硬件连接、Verilog SPI代码实现及系统调试。通过实战指南,帮助开发者快速掌握FPGA控制ADF4351芯片的技术,适用于射频信号源设计和学习应用。

weixin_30335575的博客 628

The Suspects(POJ-1611)

点我跳转 POJ - 1611 Description 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 f..

Silence的博客 243

从CCD数据上报看wxHOOK的封号风险与规避

本文深入分析了微信CCD数据上报机制对wxHOOK的检测逻辑与封号风险,揭示了调试器路径暴露、非白名单DLL加载和内存校验失败等关键风险点。通过实战案例和规避方案,帮助开发者理解如何安全使用wxHOOK技术,避免封号风险,包括内存镜像欺骗、内核级隐蔽和硬件辅助方案等高级技巧。

weixin_27875131的博客 629

从0到全栈:C#/.NET/.NET Core终极学习路线——2025年开发者必修的12个阶段与30个实战项目

【代码】从0到全栈:C#/.NET/.NET Core终极学习路线——2024年开发者必修的12个阶段与30个实战项目。

墨夶的博客 2042

A - The Suspects C语言

A - The Suspects 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 be...

qq_42754341的博客 466

GEE:哨兵时间序列遥感数据和动态阈值方法计算物候时期EOS/SOS(2)

本文将分享和解释论文《Improved Estimates of Arctic Land Surface Phenology Using Sentinel-2 Time Series》中使用到的基于阈值估算北极地区的植被物候,特别是北极地区的植被季节开始和结束的日期(SoS和EoS)的方法和代码。该方法使用的是使用哨兵2数据,并实现了两种阈值方法( 无平滑的阈值方法、平滑后的阈值方法)。

养乐多的博客 2971

poj 1611 The Suspects 【并查集基础题】

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 26901   Accepted: 13142 Description Severe acute respiratory syndrome (SARS), an atypical pneumo

世界很大 1398

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ 1611 The Suspects 并查集裸题

The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 18766 Accepted: 9075 Description Severe acute respiratory syndrome (SARS), an atypical pneum

churehill123的专栏 689

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

POJ 1611:The Suspects【并查集】【水题】

  POJ 1611:The Suspects   Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁。为了减少传播给别人的机会, 最好的策略是隔离可能的患者。 在Not-Spreading-Your-Sickness大学( NSYSU), 有许多学生团体。同一组的学生经常彼此相通,...

不甘 292

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

POJ 1611--The Suspects【并查集水题】

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 26908   Accepted: 13149 Description Severe acute respiratory syndrome (SARS), an atypical pneu

_阿阿阿阿欢 2281

poj 1611 The Suspects 并查集水题

The Suspects Time Limit: 1000MS   Memory Limit: 20000K       Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognize

yu_ming_cong的专栏 267

poj-1611 The Suspects(并查集简单题)

The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 67614 Accepted: 31979 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimi

weixin_47750287的博客 223

POJ 1611 The Suspects 并查集简单题

POJ 1611 The Suspects 并查集简单题

淘萄桃的博客 544

The Suspects POJ - 1611 并查集水题

很简单的一道并查集。/** 并查集的第二个题 哈哈 一遍过 其实很水 怕怕的过了 又有0ms的 气!! 这个题呢,就是说一个代号为0的成员,他携带病毒,如果说有人和0是一个队,那么整个团队就是带病毒的。 如果说和0一个团队的人同时也是另外一个团队的成员,那么另外一个团队的所有人都是感染病毒的。 最后要你求解的就是携带病毒的人的个数; 很水,很水,小小的用一下并查集就过去了。 就是有一个小细节

布呗之路 284

POJ1611The Suspects (并查集大水题)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 41076   Accepted: 19830 Description Severe acute respiratory syndrome (SARS), an atypical pneumo

T__TSZ的博客 267

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

并查集入门题-以POJ1611 The Suspects为例

题目: Description 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 be...

pkueecscss的博客 190

poj1611(The Suspects)-并查集基础题

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21696   Accepted: 10513 Description Severe acute respiratory syndrome (SARS), an atypical pneumo

冲鸭,胖哒哒 的专栏 504

poj 1611:The Suspects(并查集,经典题)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 Description Severe acute respiratory syndrome (SARS), an atypical pneumoni...

weixin_33758863的博客 82
上一篇: Poj3468 A Simple Problem with Integers 线段树、区间更新
下一篇: Poj1308 Is It A Tree? 并查集
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值