当前位置:网站首页>836. Merge sets (day 63) and search sets
836. Merge sets (day 63) and search sets
2022-07-03 11:45:00 【Zhangxueheng】
List of articles
Union checking set

Code
#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;
}
边栏推荐
猜你喜欢

牛牛的组队竞赛

AOSP ~ NTP ( 网络时间协议 )

DS90UB949

Web安全总结

C language AES encryption and decryption

Kubernetes 三打探针及探针方式

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

Understand go language context in one article

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

Spl06-007 air pressure sensor (example of barometer)
随机推荐
剑指offer专项32-96题做题笔记
鸿蒙第四次培训
一文搞懂Go语言Context
聊聊Flink框架中的状态管理机制
JGG专刊征稿:时空组学
CSRF
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Xml的(DTD,xml解析,xml建模)
Keepalived中Master和Backup角色选举策略
Application of high-precision indoor positioning technology in safety management of smart factory
Repo ~ common commands
PHP server interacts with redis with a large number of close_ Wait analysis
This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
CSRF
How to get started embedded future development direction of embedded
ASP.NET-酒店管理系統
[OBS] configFile in ini format of OBS
Kubernetes 三打探针及探针方式
Using onvif protocol to operate the device
简单工厂和工厂方法模式