Find them, Catch them(POJ-1703)

【题解-POJ】1703 Find them, Catch them WA,还在找BUG😩。 阅读详情

Description

The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given two criminals; do they belong to a same clan? You must give your judgment based on incomplete information. (Since the gangsters are always acting secretly.) 

Assume N (N <= 10^5) criminals are currently in Tadu City, numbered from 1 to N. And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. You will be given M (M <= 10^5) messages in sequence, which are in the following two kinds: 

1. D [a] [b] 
where [a] and [b] are the numbers of two criminals, and they belong to different gangs. 

2. A [a] [b] 
where [a] and [b] are the numbers of two criminals. This requires you to decide whether a and b belong to a same gang. 

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a line with two integers N and M, followed by M lines each containing one message as described above.

Output

For each message "A [a] [b]" in each case, your program should give the judgment based on the information got before. The answers might be one of "In the same gang.", "In different gangs." and "Not sure yet."

Sample Input

1
5 5
A 1 2
D 1 2
A 1 2
D 2 4
A 1 4

Sample Output

Not sure yet.
In different gangs.
In the same gang.

代码如下:

#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 200050
int pa[maxn];
int root(int x)
{
    return pa[x]==x?x:pa[x]=root(pa[x]);
}
void mer(int x,int y)
{
    int rx=root(x),ry=root(y);
    if(rx!=ry)
        pa[rx]=ry;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=2*n;i++)
            pa[i]=i;
        for(int i=1;i<=m;i++)
        {
            char c[2];
            int a,b;
            scanf("%s%d%d",c,&a,&b);
            if(c[0]=='A')
            {
                if(root(a)==root(b))
                    printf("In the same gang.\n");
                else if(root(a)==root(b+n)||root(b)==root(a+n))
                    printf("In different gangs.\n");
                else
                    printf("Not sure yet.\n");
            }
            else
            {
                mer(a,b+n);
                mer(b,a+n);
            }
        }
    }
    return 0;
}

poj1703 Find them, Catch them 这是题目: 3:Find them, Catch them 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, G 阅读详情

相关推荐

扣子(coze)案例^第22期:零代码打造小红书竞品监控系统+AI自动生成运营策略建议

本文详细介绍了如何利用扣子(coze)平台零代码搭建小红书竞品监控系统。该系统通过自动化工作流抓取竞品笔记数据,并存入飞书多维表格,结合AI能力自动生成包含可视化分析报告在内的运营策略建议,帮助运营者高效进行数据驱动的市场分析。

weixin_29313239的博客 1007

Find them, Catch them POJ - 1703 (带权并查集)

The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, giv.

Jin_Yanhui 277

移动端抓包实战指南:从HTTPS解密到QUIC协议与证书绑定破解

HTTPS作为保障网络通信安全的核心协议,其工作原理基于TLS/SSL加密与证书信任链验证。在移动应用开发与测试中,抓包是调试接口、分析性能、排查问题的关键技术手段。然而,随着移动端安全性的提升,传统的代理抓包方法常因证书绑定、HTTP/3/QUIC协议等挑战而失效。这要求开发者掌握分层诊断思维,协同使用代理工具、协议分析工具及底层流量捕获工具。例如,面对证书绑定导致的流量不可见,需借助Wireshark进行协议层分析;针对基于UDP的QUIC协议,则需使用支持该协议的抓包工具或临时禁用特性。本文聚焦移动端

weixin_27722377的博客 299

poj 1073 Find them, Catch them

Find them, Catch them Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the poli...

海马有力量的博客 302

领域驱动设计整理——实体和值对象设计

实体引言在领域驱动设计里,实体的设计可以说是通用语言的核心,也是最开始在模型划分中需要考虑的。怎么样设计实体和怎么样划分限界上下文同样重要。实体的概念就是要保证通用语言的完整性。领域驱动让设计实体的关注点从数据的属性和表的关联转化到了富有行为的领域概念上。 实体是具有可变性的,这是一个和值对象比较明显的区分,也即实体是可以持续得变化,持续得修改,并且具有唯一的标识。在设计实体的时候需要跳出CRUD的

马猴烧酒└(┐卍^o^)卍ドゥルルル~楪詩月「YUZURIHA SHIZUKI」 2万+

QT绘制饼图+柱状图+折线图

使用qt绘制,折线图,饼图,柱状图,多柱状图

梅山 3879

Find them, Catch them

The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which ga

Techay的博客 582

【Unity小游戏】整整一个周末写一款《皇室战争 玩法》 的 即时战斗类 游戏Demo。两万多字游戏制作过程+解析

Unity游戏制作,本篇文章介绍了复刻皇室战争玩法的一个自制小游戏,共有该游戏的两万字教程加制作过程,欢迎品尝! 世界上没有绝对的公平,如果我们起点就比别人第一步,那就更需要比别人努力了。

努力前行,总会成为自己心中的那道光 12万+

解题报告:POJ_1703Find them, Catch them 并查集

Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to i

Hee的博客~ 475

069、自动曝光(AE)测光策略:全局/中心/点测光与曝光时间增益分配

本文深入探讨了自动曝光(AE)测光策略的技术细节与实际应用。作者通过多个真实案例(手机前置摄像头、车载ADAS、安防监控等)分析了全局测光、中心测光和点测光的优缺点,指出不同场景应采用不同策略。重点剖析了曝光时间与增益分配的"跷跷板效应",提出要根据传感器特性选择最优分配方案。文章强调测光策略应动态调整,并给出5条实用建议:结合场景切换测光模式、关注传感器增益拐点、点测光需防抖处理、全局测光不宜迷信、调试要观察亮度直方图。最后指出AE调试需要结合具体硬件特性进行实测优化,没有通用解决方案。

zzfmlxs的博客 103

YOLOv12改进策略【独家融合改进】| MobileNetV4+BiFPN,轻松实现降参涨点,适用专栏内所有的骨干替换

可扩展的高效物体检测BiFPN(加权双向特征金字塔网络)

Limiiiing的博客 980

并查集

poj 1703  Find them,Catch them Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. Ho

lemon_boluo的博客 312

YOLOv8改进 | 主干网络 | 将主干网络替换为轻量化的ShuffleNetv2【原理 + 完整代码】

yolov8,yolov8创新,yolov8改进

kay_545 2567

【并查集】POJ 1703 Find them, Catch them

POJ 1703 : Find them, Catch them 有两大帮派,现在不知道每个人的帮派情况。有两种操作,D x y 表示x和y在不同帮派,A x y查询x和y的帮派情况。 如果在同一帮派,输出In the same gang. 如果不在同一帮派,输出In different gangs. 不确定帮派情况则输出Not sure yet. 这里是POJ 11...

小酷Miki的专栏 229

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

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

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ - 1703 Find them, Catch them (并查集)

                  POJ - 1703  Find them, Catch them (并查集)          这道题与食物链那一道题是同一类型的,但稍微简单些,题意就不说了                   比普通的并查集多了一个relation [i]数组,记录与父亲节点的关系,在并查集里的元素都是已经它们之间的关系的,在路径压缩与集合合并时不断的更新relation数...

GYH0730的博客 444

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

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

poj 1703 Find them, Catch them(带权并查集)

题目链接:poj 1703 Find them, Catch them 题目大意:在城市中有两个大的帮派,Gang Dragon 和Gang Snake,先在有n个人被抓了,警察队他们进行m次操作,操作分为两种,询问A a b, 要求判断a和b是不是属于同一个团伙,D a b 表示说a b不属于同一个团伙。 解题思路:带权并查集的简单版,权值为1表示和前一个人不属于同一个团

不慌不忙、不急不躁 1112

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

poj1703 Find them Catch them

http://www.elijahqi.win/2018/01/12/poj1703-find-them-catch-them/ ‎ Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city

Elijahqi 385

POJ 1703 Find them, Catch them(种类并查集)

题目地址:POJ 1703 种类并查集水题。 代码如下: #include #include #include #include #include #include #include #include #include #include #include using namespace std; int bin[600000], rank[600000]; int f

scf0920 1281

POJ1703 Find them, Catch them

题目链接:http://poj.org/problem?id=1703 大概思路:题目要确认的有三种结果,所以不能直接找出a的不同集合再与b合并。由于事先并不知道a、b是哪一派别的,所以开一个2*maxn大的数组,分成两个派别:a属于a,a属于a+maxn。每次执行D操作其实就是合并(a,b+maxn)和(a+maxn,b),最后判断a,b是否同一派别,a,b+maxn是否同一派别即可。 TL

sun_apple_123 285

Find them, Catch them POJ - 1703

The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g...

songziyuan_的博客 604

POJ 1703——Find them, Catch them【并查集变形】

题目传送门 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs ...

NIRVANA REBIRTH 249

【POJ 1703】 Find them, Catch them(关系并查集)

【POJ 1703】 Find them, Catch them(关系并查集) Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38951   Accepted: 11987 Description The police office in Tadu City

ACMer' 1309

POJ-1703-Find them, Catch them 解题报告

一道标准的关系型

JZQT_T的博客 1336

【POJ 1703 Find them, Catch them】并查集

题目链接:http://poj.org/problem?id=1703 题目大意: 给定m个操作: D x y:x罪犯和y罪犯不在一个团伙。(总共只有两个团伙) A x y:询问x和y罪犯的关系 解题思路: 很容易想到是并查集,但最后还是让我纠结了良久。一直MLE。 对于每次的D x y操作,每次不仅要找到两个不同集合标志头进行更新,还要更新a数组,即...

baidui8622的博客 90

POJ 1703: Find them, Catch them

非常基础的一道在查询时需要传递其它信息的并查集, 这方面的经典题目首推 POJ 1182 食物链 鉴于博客里没有这种类型的题目就放上来了。 写合并的时候还错误的把两个节点间的距离写成两个根节点之间的距离了, 智商捉急得简直不能多说 = =||| 题目链接:http://poj.org/problem?id=1703 题意: 有一些人分属两个帮派。 每个帮派至少有一个

frog的小池塘 952

POJ 1703 Find them, Catch them

Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24693   Accepted: 7418 Description The police office in Tadu City decides to say ends to

ACM2272902662的专栏 881
上一篇: Play on Words(HDU-1116)
下一篇: 食物链 (POJ-1182)
绿蚁.r
博客等级 码龄10年 4粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值