当前位置:网站首页>836. 合并集合(DAY 63)并查集
836. 合并集合(DAY 63)并查集
2022-07-03 10:45:00 【张学恒】
并查集

代码
#include<iostream>
using namespace std;
const int N=1000010;
int n,m;
int p[N];
int find(int x)
{
if(p[x]!=x)p[x]=find(p[x]);
return p[x];
}
int main()
{
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++)p[i]=i;
while (m -- ){
char op[2];
int a,b;
scanf("%s%d%d",op,&a,&b);
if(op[0]=='M')p[find(a)]=find(b);
else
{
if(find(a)==find(b)) puts("Yes");
else puts("No");
}
}
return 0;
}
边栏推荐
- Function details of CorelDRAW graphics suite 2022
- Program process management tool -go Supervisor
- 一些常用术语
- ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
- Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
- MATLAB提取不規則txt文件中的數值數據(簡單且實用)
- Technical experts from large factories: how can engineers improve their communication skills?
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- 银泰百货点燃城市“夜经济”
- DS90UB949
猜你喜欢

How should intermediate software designers prepare for the soft test

After using the thread pool for so long, do you really know how to reasonably configure the number of threads?

uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。

DS90UB949

Excel quick cross table copy and paste

How to clean up v$rman_ backup_ job_ Details view reports error ora-02030

Excel快速跨表复制粘贴
![[OBS] configFile in ini format of OBS](/img/b2/0b130cee6ea884557a30e4b408f49e.png)
[OBS] configFile in ini format of OBS

软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。

Web安全总结
随机推荐
如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
AOSP ~ NTP ( 网络时间协议 )
基于turtlebot3实现SLAM建图及自主导航仿真
银泰百货点燃城市“夜经济”
PHP server interacts with redis with a large number of close_ Wait analysis
Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
【学习笔记】dp 状态与转移
Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
Understand go language context in one article
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
Bi skills - permission axis
Multi dimensional monitoring: the data base of intelligent monitoring
高精度室内定位技术,在智慧工厂安全管理的应用
AMS Series 1 - AMS startup process
Internet socket (non) blocking write/read n bytes
Application of high-precision indoor positioning technology in safety management of smart factory
Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
按键切换:按F1-F12都需要按Fn
Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...