【POJ】poj 1611(并查集_裸题)

携程登录风控逆向踩坑实录:从滑块到点选验证码,我是如何一步步拿到phantom-token的 本文详细解析了携程登录风控系统的逆向过程,从滑块验证码到点选验证码的破解,再到设备指纹生成和加密协议逆向,最终成功获取phantom-token。文章提供了关键代码示例和实战技巧,帮助开发者理解并绕过复杂的风控机制。 阅读详情

 

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

题目中是要找出和0 在同一个集合里面的有几个,可以采用并查集进行搜索,首先将所有的元素插入到并查集里面继续将所有的元素遍历一边,首先如果和0

的根想通就将他算入危险行列;

 

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int people, groups;
struct group
{
    int fa;
    int ranks;
}gro[30005];
void init( int n)
{
    for ( int i = 0; i < n; i++ )
    {
        gro[i].fa = i;
        gro[i].ranks = 0;
    }
}
int finds( int x )
{
    if (gro[x].fa == x )
        return x;
    else
        return finds(gro[x].fa);
}
void unite(int x, int y)
{
    x = finds(x);
    y = finds(y);
    if ( x == y ) return ;
    if ( gro[x].ranks < gro[y].ranks )
        gro[x].fa =  y;
   else
    {
        gro[y].fa = x;
        if ( gro[x].ranks == gro[y].ranks ) gro[x].ranks++;
    }
}
bool same ( int x, int y )
{
    return finds(x) == finds(y);
}
int main()
{
    //freopen("in.txt","r",stdin);
    while ( cin >> people >> groups )
    {
        if ( people == 0 ) break;
        init(people);
        if ( groups == 0 )
        {
            cout << "1" << endl;
            continue;
        }
        int num;
        for ( int i = 0; i < groups; i++)
        {
            cin >> num;
            int first,sec;
            cin >> first;
            for ( int j = 1; j < num; j++ )
            {
                 cin >> sec;
                 unite(first,sec);
            }
        }
        int ans = 1;
        for ( int i = 1; i < people; i++ )
        {
            if ( same(0,i)) ans++;
        }
        cout << ans << endl;
    }
}

 

 

 

 

 

 

无需SLAM建图,直接生成Gazebo仿真环境的二维代价地图的功能包pgm_map_creator适配ROS Noetic编译报错及解决方法 在ROS Noetic中,使用`pgm_map_creator`功能包直接生成Gazebo仿真环境的二维代价地图时,可能会遇到各种编译和运行错误。本篇博客详细解析了在适配ROS Noetic过程中常见的报错及其解决方法,包括Boost文件结构更新、C++版本兼容性、Gazebo函数名变更、链接库缺失以及protobuf文件加载错误。通过逐步排查和修改,如更换头文件路径、调整C++标准、更新CMakeLists.txt文件等,成功解决了这些问题,使得`pgm_map_creator`功能包能够顺利编译和运行。 阅读详情

相关推荐

OpenClaw Browser Relay Extension 鉴权失败与 invalid handshake 问题的终极解决方案

在使用 OpenClaw 浏览器插件 (Browser Relay Extension) 时,许多用户可能会遇到两个主要问题:一是配置端口错误导致的连接失败,二是鉴权失败 (Gateway token rejected)。本文将详细解析这两个问题并提供解决方案。

gerryke的blog 5556

HDU 3038 带权并查集裸题

花了好长时间才明白这个到底是怎么回事。 权值其实就是各个子节点与父节点的相对距离。 带权就是表示连接到父亲节点的子节点的那条边是有权值的,我们用另外一个数组来记录这个权值(或者你用结构体也行)。 并查集这个pre数组中有很多颗树,每棵树都有自己的根节点,这一点和原先的不带权值的并查集没有区别。 有区别的是这次我们要记录子节点和父亲节点的相对距离。 举个例子: 一、a、b、c在同一棵树上

Yonggie的博客 658

宇树机器人丝滑的二人转动作背后,MPC到底是什么?

了解MPC,让我们闻“机”起舞。

Barok的博客 2144

C - How Many Tables (并查集裸题)

Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a...

cherish_lin的博客 257

1. Klipper从安装到运行

本文记录Klipper固件从安装,配置到运行的详细过程

weixin_42098934的博客 1万+

基于STM32的简易电压、频率、占空比测量仪

任务详解:我们需要实现三个功能: 第一个是测频率的功能,输入信号为频率为1kHz~10kHz的三种波形(方波、三角波、正弦波),这也是我们最常见的三种波形。幅度是不需要测量的,所以先不关心幅度。 第二个是电压报警功能,当输入信号的幅度超过15V时,我们需要报警(这里我用了一个红色LED当报警器,有条件的还可以加个蜂鸣器)并且把此时的信号幅度显示在OLED屏幕上。 第三个是通信方式的要求,需要有串口通信功能。 第四个是计算占空比的任务,这个任务的输入是幅度为1V~10V、频率为20Hz ~1kHz的方波,需要

weixin_43469377的博客 7251

并查集(大裸题)

给你一个 n 个点,m 条边的无向图,求至少要在这个的基础上加多少条无向边使得任意两个点可达~ 输入 4 2 1 2 3 4 输出 1 居然一开始看到没有立马想到并查集,ans=联通区域数-1; ACCODE: #include<bits/stdc++.h> using namespace std; int fa[100010]; int n,m; int find(int x){ if(x==fa[x])return x; else return

m0_52075409的博客 510

ARINC429协议分析

如下表所示,ARINC429在发送一帧过程中,首先发送以START开始,以END结束,共发送32bits数据,其中0~7bits为Lable数据,9~8bits为SDI数据,10~28bits为数据,29~30bits为SSM,31bit为校验位End30292827262524校验位SSM2322212019181716DATA15141312111098SDI7654321Start。

5222

并查集(模板&典型例题整理)

并查集,并查集是一种树形结构,又叫“不相交集合”,保持了一组不相交的动态集合,每个集合通过一个代表来识别,代表即集合中的某个成员,通常选择根做这个代表。 也就是说,并查集是用来处理不相交集合类型问题,如问不相交集合有几个。给定节点,找到该节点所在集合元素个数,当然这只是水题。并查集会与其他算法结合着考,如LCA中的tarjian算法。后续博客会整理。 并查集,顾名思义,主要分三部分。 一:合并

oliver233的博客 1万+

4D毫米波雷达天线设计

多种天线布局方案介绍、天线设计要点介绍

5734

OpenAI最强编程助手Codex:下载安装、使用指南(含使用方式、提示技巧、趋势)

OpenAI最近上线了最强编程Agent——Codex,一起来看看吧!

Code_流苏:在代码中寻诗意,在实践中觅真知 1万+

zcmu 1435 盟国(并查集增删裸题)

【题目】 1435: 盟国 【题意】 给定一组操作进行结盟和退盟,最后输出最终有多少个联盟。 【思路】 并查集的增删。 增。想必大家都会了不必多言。删,之前没接触过,现在来学习总结一下。 对于删除操作,在所有节点都直接连接在根节点上的并查集中,理论上只要把要删除的节点的上级重新指向自己就可以了。但是在实际情况中,我们的并查集形成的树的形态都是不可预估形态的,如果直接将一个节点指向自己...

菜鸡成长史 344

【CANdelaStudio编辑CDD】-1.2-给$10服务SessionControl创建一个新Session会话并修改Session state machine会话状态机(UDS诊断)

前一篇:【UDS诊断描述文件CDD】-1.1-ISO_14229中$10服务理论部分https://blog.youkuaiyun.com/qfmzhu/article/details/120375515案例背景: 在CDD中如何给$10服务创建一个新的Session会话; 在CDD中如何给$10服务修改Session state machine会话状态机。 目录 1 查看$10服务中已有的Session会话​ 2 查看$10服务中已有的Session state machine会话状态机 3 在$10...

「汽车电子助手」的博客 6074

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

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

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

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

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 best

SCUT_Pein 620

OV9734 DATASHEET,完整规格书

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

并查集入门三连:HDU1213 POJ1611 POJ2236

HDU1213 http://acm.hdu.edu.cn/showproblem.php?pid=1213 问题描述 今天是伊格纳修斯的生日。他邀请了很多朋友。现在是晚餐时间。伊格纳修斯想知道他至少需要多少桌子。你必须注意到并非所有的朋友都互相认识,而且所有的朋友都不想和陌生人呆在一起。 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,那意味着A,B,C彼此了解,所以他们可以留在...

少说,多做。 3610

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ 1611 The Suspects 【并查集基础】

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

指弹键盘哼民谣 559

POJ 1611 并查集

POJ 1611 并查集 The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 53197 Accepted: 25301 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aeti...

weixin_43971913的博客 241

【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

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

【并查集】POJ-1611

/* POJ-1611 并查集(基础题) ①带路径压缩的查找 ②合并:先判断是否在同一集合,合并操作执行的条件是2元素不在同一集合 */ #include #define N 30001 int set[N]; int elemNum[N]; void initialize(int n); int findSet(int a); void unionSet(int a, int b); in

码农 617

POJ 1611 (并查集)

 POJ 1611 学了并查集后 这个就很easy啦~ #include &lt;iostream&gt;using namespace std;int m,n,first;int father[30005],num[30005];void makeSet(int n){ for(int i=0;i&lt;n;i++){ father[i]=i; num[i]=1...

weixin_34019144的博客 139

poj1611(并查集)

先说并查集的概念:          并查集处理的是求在树中,求某些元素是否在同一个集合。这种操作不关注同一个集合中某些点的邻接关系,只关心他们是否在同一个集合中。其中的操作有三种分别是合并两个集合,查询一个元素在哪个集合,查询两个元素是否在同一个集合。处理方法用一个数组par[]记录每个节点的根结点,一开始将每个节点的根结点初始化为自身,随后由给出的邻接点修改该数组的值,之后不断地把任意节点直

YanzheShi的专栏 674

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

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

POJ_1611(并查集问题)

POJ_1611,并查集算法例题,由于没有压缩路径故leader[stu]是stu的直接leader 。 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int leader[30000]; int findleader(int stu){ if(st...

宫·商的博客 206
上一篇: 【HDU】hdu 1081 (dp_区间dp)
下一篇: 【POJ】poj 1988(并查集_点到跟的距离)
三生石1103
博客等级 码龄12年 16粉丝 87原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值