当前位置:网站首页>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;
}
边栏推荐
- Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
- C语言日志库zlog基本使用
- 如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
- Oracle 11g single machine cold standby database
- Function details of CorelDRAW graphics suite 2022
- 多维度监控:智能监控的数据基础
- Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
- The excel table is transferred to word, and the table does not exceed the edge paper range
- How should intermediate software designers prepare for the soft test
- The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
猜你喜欢

Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises

进程与线程

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

This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system

银泰百货点燃城市“夜经济”

多维度监控:智能监控的数据基础

PHP server interacts with redis with a large number of close_ Wait analysis

一文搞懂Go语言Context

Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.

00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
随机推荐
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
Function details of CorelDRAW graphics suite 2022
Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Analysis of EPS electric steering system
一文搞懂Go语言Context
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Phpcms prompt message page Jump showmessage
How to mix embedded MCU, arm and DSP?
AMS Series 1 - AMS startup process
Asyncio warning deprecationwarning: there is no current event loop
Analysis of JMM memory model
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
Static library vs shared library
asyncio 警告 DeprecationWarning: There is no current event loop
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
Using onvif protocol to operate the device
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system