当前位置:网站首页>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;
}
边栏推荐
- DS90UB949
- The world's most popular font editor FontCreator tool
- Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
- How to: configure ClickOnce trust prompt behavior
- Analysis of JMM memory model
- VPP三层网络互联配置
- Oracle 11g single machine cold standby database
- 动态规划(区间dp)
- Arctangent entropy: the latest SCI paper in July 2022
- repo ~ 常用命令
猜你喜欢
PHP server interacts with redis with a large number of close_ Wait analysis
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
抓包整理外篇fiddler———— 会话栏与过滤器[二]
FL Studio 20 unlimited trial fruit arranger Download
Processes and threads
高精度室内定位技术,在智慧工厂安全管理的应用
How should intermediate software designers prepare for the soft test
鸿蒙第四次培训
基于turtlebot3实现SLAM建图及自主导航仿真
C language AES encryption and decryption
随机推荐
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
Application of high-precision indoor positioning technology in safety management of smart factory
动态规划(区间dp)
[vtk] source code interpretation of vtkpolydatatoimagestencil
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
POI excel cell wrap
Web安全总结
Android log system
Redis things
Static library vs shared library
[VTK] vtkPolydataToImageStencil 源码解读
如何将数字字符串转换为整数
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func mai
How to make others fear you
Viewing binary bin files with notepad++ editor
Double linked list of linear list