#include<iostream>
#include<cstdio>
#include<cstring>
const int MAXN=200020;
int n,m;
int set[MAXN];
int set_find(int d)
{
if(set[d]<0)
return d;
else
return set[d]=set_find(set[d]);
}
int main()
{
int loop;
scanf("%d",&loop);
while(loop--)
{
scanf("%d%d",&n,&m);
memset(set,-1,sizeof(set));
for(int i=0;i<m;i++)
{
int a,b;
char s[5];
scanf("%s%d%d",s,&a,&b);
if(s[0]=='A')
{
if(set_find(a)!=set_find(b)&&set_find(a)!=set_find(b+n))
printf("Not sure yet.\n");
else if(set_find(a)==set_find(b))
printf("In the same gang.\n");
else
printf("In different gangs.\n");
}
else{
if(set_find(a)!=set_find(b+n))
{
set[set_find(a)]=set_find(b+n);
set[set_find(b)]=set_find(a+n);
}
}
}
}
return 0;
}
相关推荐
遥感影像分割实战:LoveDA数据集从下载到训练全流程指南(附避坑技巧)
本文以LoveDA数据集为例,提供了一份详尽的遥感影像语义分割实战指南。内容涵盖从数据下载、理解与预处理,到环境配置、模型选择与训练,再到性能调优与部署的全流程,并重点分享了多个关键环节的避坑技巧,旨在帮助开发者和研究者高效上手并解决实际问题。
poj--1703 Find them, Catch them(并查集)
problem link题解对于 D a b,a和b属于不同的帮派,如果a属于帮派A,那么a + n属于帮派B,同理,b也是如此。 因此,并查集中元素的个数是2n,每次合并就是Union(a, b + n) 和 Union(a + n, b) 这实际上是保留了所有的可能性,因为只知道a和b不在同一个集合里,不能确定到底是属于哪个集合。#include <iostream> #include <a
复古与新生:老毛子Padavan固件在旧设备上的现代化应用之旅
本文探讨了如何通过刷入Padavan固件,让小米路由器3G(R3G)等老旧设备重获新生,实现现代化应用。详细介绍了从硬件潜力分析、智能家居中枢搭建,到轻量级服务器部署和网络功能扩展的全过程,为技术爱好者提供了一条低成本、高性能的设备改造之路。
POJ1703 Find them, Catch them【并查集】
Find them, Catch themTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 50328 Accepted: 15453DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to roo...
【Tessent Shell Users Manual】【Ch3】Design Introspection and Editing(未完待续)
Tessent Shell 提供了一系列用于检查(examining/introspecting)和编辑design的命令。
腾讯云TDSQL MySQL版 - 开发指南兼容性
语言结构 分布式实例支持所有 MySQL 使用的文字格式,包括: String Literals Numeric Literals Date and Time Literals Hexadecimal Literals Bit-Value Literals Boolean Literals NULL Values String Literals String Literals 是一个 bytes 或者 characters 的序列,两端被单引号'或者双引号"包围,TDSQL MySQL版
【并查集】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...
Google AI Skills Badge 30天实战路径:从Prompt工程到AI工作流落地
提示工程(Prompt Engineering)是人机协同的核心能力,本质是将模糊业务意图精准转译为机器可执行、可验证的指令流。其原理植根于大语言模型的token匹配机制与上下文理解范式,技术价值在于突破传统自动化边界,实现低代码、高适应性的AI应用构建。典型应用场景覆盖客户服务归类、财报摘要生成、邮件智能分析等企业高频任务。本路径以Google官方AI Skills Badge为载体,融合神经科学验证的30天学习节拍、结构化输出设计、AI响应可信度评估等关键实践,突出Prompt Engineering与
POJ - 1703 Find them, Catch them (并查集)
POJ - 1703 Find them, Catch them (并查集) 这道题与食物链那一道题是同一类型的,但稍微简单些,题意就不说了 比普通的并查集多了一个relation [i]数组,记录与父亲节点的关系,在并查集里的元素都是已经它们之间的关系的,在路径压缩与集合合并时不断的更新relation数...
因子数据预处理-去极值和标准化
多因子数据预处理
Python与CAD系列基础篇(十)图形复制、移动、删除
①通过pyautocad连接AutoCAD进行处理②通过ezdxf处理dxf格式文件。进行图形复制、移动、删除的方法。pyautocad方式。pyautocad方式。
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表示和前一个人不属于同一个团
淋巴结病理数字玻片读取与处理代码
Whole-slide images are generally stored in a multi-resolution pyramid structure. 首先安装openslide模块 pip install openslide-python import os.path as osp import openslide from pathlib import Path...
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
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
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
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
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 ...
假人有限元模型
假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用
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
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...
POJ-1703-Find them, Catch them 解题报告
一道标准的关系型
【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
POJ 1703: Find them, Catch them
非常基础的一道在查询时需要传递其它信息的并查集, 这方面的经典题目首推 POJ 1182 食物链 鉴于博客里没有这种类型的题目就放上来了。 写合并的时候还错误的把两个节点间的距离写成两个根节点之间的距离了, 智商捉急得简直不能多说 = =||| 题目链接:http://poj.org/problem?id=1703 题意: 有一些人分属两个帮派。 每个帮派至少有一个
【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数组,即...
POJ1703Find them, Catch them 【种类并查集】
题目链接:http://poj.org/problem?id=1703 题目大意:给n个人,m次询问。A代表询问a, b之间的关系,D代表给出a, b属于不同的帮派。 我的想法: 太菜了,上课的时候没想到这种方法。 思路: 1.感觉有点像2-sat的思想,对于D给出的a, b两人属于不同帮派。我们就将a于b的对立点用并查集维护在一个集合中,也将b于a的对立点连通。 2.查询时...
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
并查集:POJ No1703 Find them, Catch them
并查集:POJ No1703 Find them, Catch them 题目链接:http://poj.org/problem?id=1703 题意:两个坏蛋属于不同的组织,给出两个坏蛋判定是否一个组织。 题解:已知每次输入的两个帮派人员 x, y; 合并 (x, y + N), (x + N, y)。判定时,如果 (x, y) 属于同一个 ...
934




被折叠的 条评论
为什么被折叠?



