当前位置:网站首页>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;
}
边栏推荐
- Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
- The world's most popular font editor FontCreator tool
- This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
- 抓包整理外篇fiddler———— 会话栏与过滤器[二]
- Yintai department store ignites the city's "night economy"
- 解决msvcp120d.dll和msvcr120d.dll缺失
- R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
- Internet socket (non) blocking write/read n bytes
- 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
- Web security summary
猜你喜欢

Groovy测试类 和 Junit测试

用了这么久线程池,你真的知道如何合理配置线程数吗?

Analysis of EPS electric steering system

量化计算调研

牛牛的组队竞赛

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

836. 合并集合(DAY 63)并查集

After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good

VS2015的下载地址和安装教程

Application of high-precision indoor positioning technology in safety management of smart factory
随机推荐
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
MCDF实验1
Some common terms
Kibana - installation and configuration of kibana
AOSP ~ NTP ( 网络时间协议 )
STL教程10-容器共性和使用场景
PHP server interacts with redis with a large number of close_ Wait analysis
Uniapp implementation Click to load more
Multi dimensional monitoring: the data base of intelligent monitoring
FL Studio 20 unlimited trial fruit arranger Download
Extrapolated scatter data
用了这么久线程池,你真的知道如何合理配置线程数吗?
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Arctangent entropy: the latest SCI paper in July 2022
previous permutation lintcode51
Hongmeng third training (project training)
如何将数字字符串转换为整数
typeScript
GCC compilation process and dynamic link library and static link library
一文搞懂Go语言Context