当前位置:网站首页>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;
}
边栏推荐
- 00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
- GCC compilation process and dynamic link library and static link library
- phpcms 提示信息頁面跳轉showmessage
- Excel quick cross table copy and paste
- Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
- Oracle 11g single machine cold standby database
- Linear table sequence table comprehensive application problem p18
- R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- The manuscript will be revised for release tonight. But, still stuck here, maybe what you need is a paragraph.
- AMS Series 1 - AMS startup process
猜你喜欢

Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3

基于I2C协议的驱动开发

How should intermediate software designers prepare for the soft test

C语言 AES加解密

DS90UB949

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

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

After a month, I finally got Kingdee offer! Share tetrahedral Sutra + review materials

AMS Series 1 - AMS startup process

进程与线程
随机推荐
Google Earth engine (GEE) -- when we use the front and back images to make up for the interpolation effect, what if there is no effect?
如何将数字字符串转换为整数
Execute kubectl on Tencent cloud container service node
MATLAB提取不规则txt文件中的数值数据(简单且实用)
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
Oracle 11g single machine cold standby database
Programmers' entrepreneurial trap: taking private jobs
一些常用术语
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
AMS series - application startup process
Project management essence reading notes (6)
Spl06-007 air pressure sensor (example of barometer)
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
Web安全总结
Tablespace creation management and control file management
Application of high-precision indoor positioning technology in safety management of smart factory
DS90UB949
How to make others fear you
机器学习 3.2 决策树模型 学习笔记(待补)
Android log system