当前位置:网站首页>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;
}
边栏推荐
- Understand go language context in one article
- Project management essence reading notes (VII)
- GCC compilation process and dynamic link library and static link library
- This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
- Oracle withdraw permission & create role
- 程序员的创业陷阱:接私活
- Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
- 鸿蒙第三次培训(项目实训)
- 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
- ASP. Net hotel management system
猜你喜欢

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

Cadence background color setting

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

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

FL Studio 20无限试用版水果编曲下载

C language AES encryption and decryption

FL Studio 20 unlimited trial fruit arranger Download

Based on MCU, how to realize OTA differential upgrade with zero code and no development?

Spl06-007 air pressure sensor (example of barometer)

(2) Base
随机推荐
Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
Mmc5603nj geomagnetic sensor (Compass example)
按键切换:按F1-F12都需要按Fn
Machine learning 3.2 decision tree model learning notes (to be supplemented)
R语言使用原生包(基础导入包、graphics)中的hist函数可视化直方图(histogram plot)
Struct function & function pointer
Redis things
POI excel cell wrap
Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
Solicitation for JGG special issue: spatio-temporal omics
Qt+VTK+OCCT读取IGES/STEP模型
(2) Base
Viewing binary bin files with notepad++ editor
Bi skills - permission axis
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
Understand go language context in one article
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3