当前位置:网站首页>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;
}
边栏推荐
- How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
- 1. Hal driven development
- 软考中级软件设计师该怎么备考
- asyncio 警告 DeprecationWarning: There is no current event loop
- 2. Hal hardware abstraction layer
- Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
- FL Studio 20无限试用版水果编曲下载
- Struct function & function pointer
- R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
- Reading notes: heart like Bodhi, Cao Dewang
猜你喜欢

(2) Base

uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。

Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution

LeetCode 46:全排列

Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable

Excel quick cross table copy and paste

Matlab extracts numerical data from irregular txt files (simple and practical)

Intel 13th generation core flagship exposure, single core 5.5ghz

FL Studio 20 unlimited trial fruit arranger Download

Qt+VTK+OCCT读取IGES/STEP模型
随机推荐
Key switch: press FN when pressing F1-F12
Machine learning 3.2 decision tree model learning notes (to be supplemented)
Execute kubectl on Tencent cloud container service node
C language AES encryption and decryption
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
Reading notes: heart like Bodhi, Cao Dewang
基于I2C协议的驱动开发
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
Illustrated network: what is virtual router redundancy protocol VRRP?
CSRF
2. Hal hardware abstraction layer
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Intel 13th generation core flagship exposure, single core 5.5ghz
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
银泰百货点燃城市“夜经济”
The world's most popular font editor FontCreator tool
Understand go language context in one article
Tablespace creation management and control file management
C language log base zlog basic use