poj 1611 The Suspects 并查集

NanoTrack 模型从 PyTorch 到 RK3588 的 RKNN 转换与部署实战 模型转换是将训练框架计算图翻译为 NPU 可执行指令的关键环节,涉及算子映射、动态 shape 处理和量化校准等核心技术。在边缘计算场景中,RK3588 凭借 6 TOPS NPU 算力成为部署轻量级跟踪模型的热门平台,而 NanoTrack 作为高效单目标跟踪网络,其 PyTorch 到 RKNN 的迁移过程需要经过 ONNX 中间格式桥接,并解决算子兼容性与 INT8 量化精度问题。该流程广泛应用于智能安防、无人机图传等实时跟踪场景,通过合理的校准集构建与混合量化策略,可在板端实现 60 FPS 以上的 阅读详情

The Suspects,题目链接,点这里。

Time Limit: 1000MS Memory Limit: 20000K
Total Submissions: 31216 Accepted: 15162
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

Asia Kaohsiung 2003

中文翻译

Description

严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁。为了减少传播给别人的机会, 最好的策略是隔离可能的患者。 
在Not-Spreading-Your-Sickness大学( NSYSU), 有许多学生团体。同一组的学生经常彼此相通,一个学生可以同时加入几个小组。为了防止非典的传播,NSYSU收集了所有学生团体的成员名单。他们的标准操作程序(SOP)如下: 
一旦一组中有一个可能的患者, 组内的所有成员就都是可能的患者。 
然而,他们发现当一个学生被确认为可能的患者后不容易识别所有可能的患者。你的工作是编写一个程序, 发现所有可能的患者。 

Input

输入文件包含多组数据。 
对于每组测试数据: 
第一行为两个整数n和m, 其中n是学生的数量, m是团体的数量。0 < n <= 30000,0 <= m <= 500。 
每个学生编号是一个0到n-1之间的整数,一开始只有0号学生被视为可能的患者。 
紧随其后的是团体的成员列表,每组一行。 
每一行有一个整数k,代表成员数量。之后,有k个整数代表这个群体的学生。一行中的所有整数由至少一个空格隔开。 
n = m = 0表示输入结束,不需要处理。

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

题意已经很清楚了,那么现在就是将代码实现的过程了。
一开始就是感觉并查集,直接最后找一遍父节点比较0的父节点就可以了。

#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
const int maxn = 30005;
int father[maxn];//存储
//初始化;
void init(int n)
{
    for(int i=0;i<=n;i++)
        father[i]=i;
}
//找爹函数;路径压缩;
int get(int t)
{
    if(t!=father[t])
        father[t]=get(father[t]);
    return father[t];
}
//合并函数;
void  Merge(int a,int b)
{
    int t1=get(a),t2=get(b);
    if(t1!=t2)
    {
        if(father[t1]<father[t2])//归并小的父节点给大的;
            father[t2]=t1;
        else
            father[t1]=t2;
    }
    return ;
}

int main()
{
    int n,m,t;
    int c,b,a,f;
    while(~scanf("%d%d",&n,&m),n+m)
    {
        init(n);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&t,&f);
            for(int i=1;i<t;i++)
            {
                scanf("%d",&a);
                Merge(f,a);//直接合并;
            }
        }
        int coun=1;
        b=father[0];//0 的父节点;

        //遍历一遍,找父节点,比较;
        for(int i=1;i<=n;i++)
            if(get(i)==b)
                coun++;
        printf("%d\n",coun);
    }
    return 0;
}
从 0 到 1,实战 Power BI 电商销售可视化看板全流程 本文详细介绍了从零开始使用Power BI构建电商销售可视化看板的全流程,涵盖数据准备、建模、可视化设计及高级功能应用。通过实战案例展示如何将复杂销售数据转化为直观图表,帮助电商从业者快速掌握销售趋势、热销产品和用户画像等关键信息,提升数据分析效率。 阅读详情

相关推荐

Redis中什么是Big Key(大key)问题?如何解决Big Key问题?

通俗易懂的讲,Big Key就是某个key对应的value很大,占用的redis空间很大,本质上是大value问题。key往往是程序可以自行设置的,value往往不受程序控制,因此可能导致value很大。redis中这些Big Key对应的value值很大,在序列化/反序列化过程中花费的时间很大,因此当我们操作Big Key时,通常比较耗时,这就可能导致redis发生阻塞,从而降低redis性能。用几个实际的例子对大Key的特征进行描述:● 一个String类型的Key,它的值为5MB(数据过大); ● 一

weixiaohuai的博客 3万+

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

C# 开发 WPS 插件实战:从环境搭建到功能实现(附完整代码)

本文提供了一份详尽的C#开发WPS插件实战指南,涵盖从环境搭建到功能实现的完整流程。通过COM技术,开发者可以创建自定义插件,为WPS Office扩展自动化功能,如文档处理与格式转换。文章包含核心概念解析、Ribbon界面集成、调试部署方法及完整代码示例,帮助开发者快速上手。

rust6ferris的博客 927

kuangbin 并查集 - POJ - 1611 The Suspects (并查集模板题)

kuangbin 并查集 - POJ - 1611 The Suspects (并查集模板题) 传送门 Click here ~~ 题意: 小明被确诊了非典病毒,小明必须被隔离治疗,并且与他直接或间接接触者都要隔离观察。同一个社团内如果有人感染病毒或可能感染病毒,那么这个社团内所有人都被认为是可能已经感染了病毒,由于时间紧迫,需要尽快找到所有可能携带病毒的同学并隔离,以防止更大范围的病毒扩散,院长请你帮忙编写程序计算需要隔离多少人。 题解:模板题。 Click here ~~~ 可以看一下这个并查集模板

ACM-ICPC 现役(铜牌) Codeforces Rating: 2172 257

element的el-cascader组件动态加载,以及报错处理问题

Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. 报错处理

weixin_56527169的博客 1262

华为OD机试真题 新系统 2026-07-22 Java&Go&C 实现【最小代价完成论文评审】

某校有 n 篇论文需要分配给教师评审。 每篇论文 i 可由 files[i] 对应的教师列表中任一教师评审。 每篇论文至少需要一名教师评审。 每位教师 t 不论被分配多少篇论文,其评审费用固定为 cost[t]。 请给出参与评审教师数量最少时的总费用。 如果存在多种方案满足教师数量最少,则选择总费用最小的方案。

MISAYAONE的博客 148

【并查集-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

【WRF安装第三期(Ubuntu)】搭建WRF编译所需系统-第三方依赖库安装

WRF安装第三期:搭建WRF编译所需系统-第三方依赖库安装

WW、forever的博客 3137

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的博客 141

claude code desktop中出现Doesn‘t look like an Anthropic model - expected a gateway model route 解决方案

本文主要介绍了claude code desktop中出现Doesn’t look like an Anthropic model - expected a gateway model route referencing an Anthropic model和Server is busy. Retrying的解决方案,希望能对使用claude code desktop的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 9万+

华为od面试手撕真题【分解质因数】

华为od面试手撕真题【分解质因数】

MISAYAONE的博客 1133

【解题报告】 POJ 1611 The Suspects 并查集基础 (一点自己的感悟)

题目连接:POJ 1611 最最基础的并查集题目,我就不说什么了。 // POJ1611 The Suspects 并查集 //初始化 所有点的父节点初始为-1 //查找(找到两点的祖先),合并(合并两个点的祖先) //由于我们事先开了数组记录了祖先的所有所有结点数(办法是进来一个新的结点,则num[祖先]+=num[新节点]) // //还有我感觉并查集有点类似于 皇帝->大臣->县令->师

生命有一种绝对 694

从 QQ 聊天到 AI Agent:AstrBot + NapCat 接入 DeepSeek

<think>我们根据要求,根据提供的内容生成≤150字的文章摘要。内容是关于在Windows上使用Docker部署AstrBot+NaPCat,配置DeepSeek,实现QQ AI机器人。摘要需简洁概括主要步骤和结论。注意字数。</think>在Windows 11上通过Docker一键部署AstrBot与NapCat,实现QQ机器人。NapCat扫码登录QQ,AstrBot接入并配置DeepSeek API,完成AI对话。后续可扩展人格、插件及MCP工具,并通过cpolar提供公网管理入口,打造可扩展的

天道酬勤 1万+

POJ.1611 The Suspects (并查集)

POJ.1611 The Suspects (并查集)题意分析对于每组测试数据: 这个学校有n个人,m小组,依次给出m个小组的信息,每行一个小组。 每个小组的信息包括,k,表示有k个人,k个数字,分别是这k个人的ID。 现在ID为0的人感染了病毒,他及他的小组成员全部会感染病毒,每个小组成员都会感染自己所在小组的成员(每个成员可以加入多个小组)。问现在总共有多少个人感染了病毒? 比较裸的并查

Pengwill's Blog 300

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

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Poj 1611 The Suspects【并查集】

POJ The Suspects POJ - 1611 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 o...

qq_28640193的博客 255

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

POJ 1611The Suspects(并查集)

POJ 1611The Suspects(并查集) vj链接 Solution 并查集模板题,最后找一遍有多少和 0 点在同一集合即可。 代码 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<cmath> #include<string&

weixin_53177273的博客 142

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ 1611 The Suspects (并查集)

链接:http://poj.org/problem?id=1611 The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 20031   Accepted: 9730 Description Severe acute respira

Epic丶玖遇 896

POJ 1611 The Suspects 【并查集基础】

POJ 1611 The Suspects 题目大意: 有n个人,m个社团,有一种病毒具有传染性,假设一个人可能感染,那么它所属社团的所有人都可能感染, 假设0号这个人疑似感染了病毒,问总共有多少人可能感染病毒 具体思路: 并查集模板题 具体代码: #include<iostream> #include<cstdio> #include<algorithm> u...

指弹键盘哼民谣 559

POJ 1611 The Suspects (并查集)不相交集合+合并优化

传送门:POJ 1611 The Suspects (并查集)题目大意有很多组学生,在同一个组的学生经常会接触,也会有新的同学的加入。但是SARS是很容易传染的,只要在改组有一位同学感染SARS,那么该组的所有同学都被认为得了SARS。现在的任务是计算出有多少位学生感染SARS了。假定编号为0的同学是得了SARS的。解题思路向这种题目明显是并查集的一种变形叫不相交并查集。 父节点里面保存的是元素的

woshinannan的专栏 436

poj 1611 :The Suspects经典的并查集题目

poj 1611 :The Suspects    Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-M...

蒟蒻的博客 227

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

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

【POJ 1611 --- The Suspects】并查集 题目来源:点击进入【POJ 1611 — The Suspects】 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in...

来日浅谈的博客 533

The Suspects POJ - 1611 并查集

一、内容 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...

Tizzi的博客 3472

POJ——1611 The Suspects(并查集)

原题链接: http://poj.org/problem?id=1611 测试样例 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 题意: 有nnn个学生和mmm个小组,其中每个学生可以加入多个小组。学生编号从000到n−1n-1n−1,现在有一个规定,若一个小组中有一个是疑似SARS感染者,那么该小组其他人也会被认为是SARS感染者。现在学

pursuit的博客 548

POJ1611 The Suspects 并查集

没什么好说的,建立n的并查集,把每个group的人都连起来,最后遍历一遍即可。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF 0x3f3f3f3f #define in

PrimeG的博客 358

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
上一篇: hdu 1716 排列2 (全排列)
下一篇: hdu 1029 Ignatius and the Princess IV 很简单的一道题。
落幕丶式
博客等级 码龄11年 2粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值