当前位置:网站首页>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;
}
边栏推荐
- 2022年湖南工学院ACM集训第二次周测题解
- After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
- Technical experts from large factories: how can engineers improve their communication skills?
- 聊聊Flink框架中的状态管理机制
- MCDF实验1
- 利用Zabbix动态监控磁盘I/O
- 同事写了一个责任链模式,bug无数...
- P3250 [hnoi2016] Network + [necpc2022] f.tree path tree section + segment tree maintenance heap
- 一些常用术语
- After setting up ADG, instance 2 cannot start ora-29760: instance_ number parameter not specified
猜你喜欢

(database authorization - redis) summary of unauthorized access vulnerabilities in redis

Viewing binary bin files with notepad++ editor
![抓包整理外篇fiddler———— 会话栏与过滤器[二]](/img/04/e9cc027d753e7049f273d866eefdce.png)
抓包整理外篇fiddler———— 会话栏与过滤器[二]

一文搞懂Go语言Context

机器学习 3.2 决策树模型 学习笔记(待补)

ASP.NET-酒店管理系統

FL Studio 20 unlimited trial fruit arranger Download

Kibana - installation and configuration of kibana

Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power

The world's most popular font editor FontCreator tool
随机推荐
Modular programming of single chip microcomputer
DS90UB949
(数据库提权——Redis)Redis未授权访问漏洞总结
STL教程9-容器元素深拷贝和浅拷贝问题
ASP. Net hotel management system
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
Application of high-precision indoor positioning technology in safety management of smart factory
Viewing binary bin files with notepad++ editor
ASP.NET-酒店管理系統
How should intermediate software designers prepare for the soft test
STL教程10-容器共性和使用场景
POI excel cell wrap
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
同事写了一个责任链模式,bug无数...
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
Asyncio warning deprecationwarning: there is no current event loop
量化计算调研
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
Cadence background color setting
Visual Studio 2022下载及配置OpenCV4.5.5