当前位置:网站首页>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;
}
边栏推荐
- 解决msvcp120d.dll和msvcr120d.dll缺失
- C language AES encryption and decryption
- 机器学习 3.2 决策树模型 学习笔记(待补)
- DS90UB949
- The world's most popular font editor FontCreator tool
- Unity3D学习笔记5——创建子Mesh
- R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
- ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
- Redis things
- .\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
猜你喜欢
How to get started embedded future development direction of embedded
Qt+VTK+OCCT读取IGES/STEP模型
Hongmeng third training (project training)
Redis things
2022 northeast four provinces match VP record / supplementary questions
Cadence background color setting
多维度监控:智能监控的数据基础
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
DS90UB949
Excel快速跨表复制粘贴
随机推荐
Slam mapping and autonomous navigation simulation based on turnlebot3
软考中级软件设计师该怎么备考
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
C语言 AES加解密
The excel table is transferred to word, and the table does not exceed the edge paper range
Mysql根据时间搜索常用方法整理
Sheet1$.输出[Excel 源输出].列[XXX] 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项。”。
STL教程9-容器元素深拷贝和浅拷贝问题
Uniapp implementation Click to load more
ASP.NET-酒店管理系统
How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression
ftp登录时,报错“530 Login incorrect.Login failed”
在CoreOS下部署WordPress实例教程
ASP. Net hotel management system
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
Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
聊聊Flink框架中的状态管理机制
phpcms 提示信息頁面跳轉showmessage
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
Viewing binary bin files with notepad++ editor