当前位置:网站首页>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;
}边栏推荐
- Idea shortcut keys
- 竞品分析撰写
- x Problem B
- Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
- Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
- 深潜Kotlin协程(十九):Flow 概述
- [fxcg] market analysis today
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- JS实现图片懒加载
- Xrandr modify resolution and refresh rate
猜你喜欢

CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
![[fxcg] market analysis today](/img/ac/294368e3496a5b808b38833053ee81.jpg)
[fxcg] market analysis today

Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积

【刷题篇】 找出第 K 小的数对距离

IPv6 foundation construction experiment

有监督预训练!文本生成又一探索!

因果AI,下一代可信AI的产业升级新范式?

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

Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练

Mutex and rwmutex in golang
随机推荐
xrandr修改分辨率与刷新率
redis 持久化原理
[Yu Yue education] reference materials of political communication science of Communication University of China
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
Interface embedded in golang struct
JS实现图片懒加载
QSAR model establishment script based on pytoch and rdkit
Square root of X
Redraw and reflow
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
[set theory] inclusion exclusion principle (including examples of exclusion principle)
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
Database management tool, querious direct download
[fxcg] market analysis today
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
Basic MySQL operations
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions