当前位置:网站首页>Joint search set: the number of points in connected blocks (the number of points in a set)
Joint search set: the number of points in connected blocks (the number of points in a set)
2022-07-03 04:18:00 【zheng. ys】


#include<iostream>
using namespace std;
const int N=100010;
int n,m;
int p[N];
int size[N];
// return x The ancestor node of + Path compression
// Path compression : Point each node to its ancestor node
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
scanf("%d%d",&n,&m);
// initialization : Point the ancestor node of each node to itself
for(int i=1;i<=n;i++)
{
p[i]=i;
size[i]=1;
}
while(m--)
{
char op[5];
int a,b;
scanf("%s",op);
if(op[0]=='C')// Merge nodes
{
scanf("%d%d",&a,&b);
if(find(a)==find(b))
continue;
size[find(b)]+=size[find(a)];
p[find(a)]=find(b);
}
else if(op[1]=='1')
{
scanf("%d%d",&a,&b);
if(find(a)==find(b))
puts("Yes");
else
puts("No");
}
else
{
scanf("%d",&a);
printf("%d\n",size[find(a)]);
}
}
return 0;
}边栏推荐
- 2022-02-12 (338. Bit count)
- Interface embedded in golang struct
- Arduino application development - LCD display GIF dynamic diagram
- JMeter starts from zero (III) -- simple use of regular expressions
- Database management tool, querious direct download
- [fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
- JS实现图片懒加载
- Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness
- How to connect WiFi with raspberry pie
- 多板块轮动策略编写技巧----策略编写学习教材
猜你喜欢

Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
![[dynamic programming] subsequence problem](/img/d8/020ae959ef53ce097d3a81a0d2d63a.jpg)
[dynamic programming] subsequence problem

金仓KFS数据双向同步场景部署

用户体验五要素

使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错

Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?

Interaction free shell programming

CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强

Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
![[NLP]—sparse neural network最新工作简述](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[NLP]—sparse neural network最新工作简述
随机推荐
Arduino application development - LCD display GIF dynamic diagram
Interface in TS
Five elements of user experience
因子选股-打分模型
[graduation season · aggressive technology Er] Confessions of workers
Sklearn data preprocessing
会员积分商城系统的功能介绍
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
Deep dive kotlin synergy (19): flow overview
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
服务器无法远程连接原因分析
xrandr修改分辨率與刷新率
金仓数据库KingbaseES 插件kdb_date_function
mysql字段userid逗号分开保存按userid查询
Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
Social phobia of contemporary young people (II)
IPv6 foundation construction experiment
300+篇文献!一文详解基于Transformer的多模态学习最新进展
When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker