当前位置:网站首页>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;
}
边栏推荐
- R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- Numpy np. Max and np Maximum implements the relu function
- R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
- 鸿蒙第四次培训
- phpcms 提示信息頁面跳轉showmessage
- Modular programming of single chip microcomputer
- Project management essence reading notes (VII)
- ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
- phpcms 提示信息页面跳转showmessage
- Linear table sequence table comprehensive application problem p18
猜你喜欢

ASP.NET-酒店管理系統

软考中级软件设计师该怎么备考

Excel quick cross table copy and paste

Application of high-precision indoor positioning technology in safety management of smart factory

鸿蒙第三次培训(项目实训)

Qt+VTK+OCCT读取IGES/STEP模型

Viewing binary bin files with notepad++ editor

聊聊Flink框架中的状态管理机制

Incremental database backup - DB incr DB full

How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
随机推荐
00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
How to get started embedded future development direction of embedded
Qt+VTK+OCCT读取IGES/STEP模型
机器学习 3.2 决策树模型 学习笔记(待补)
鸿蒙第四次培训
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
phpcms 提示信息页面跳转showmessage
CSRF
How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression
PHP server interacts with redis with a large number of close_ Wait analysis
鸿蒙第三次培训(项目实训)
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
CSRF
Mmc5603nj geomagnetic sensor (Compass example)
[OBS] encapsulate the basic process of OBS acquisition
Multi dimensional monitoring: the data base of intelligent monitoring
【学习笔记】dp 状态与转移
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
如何将数字字符串转换为整数
AMS series - application startup process