当前位置:网站首页>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;
}边栏推荐
- vim 的实用操作
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- Taking two column waterfall flow as an example, how should we build an array of each column
- 竞品分析撰写
- 540. Single element in ordered array
- Application of I2C protocol of STM32F103 (read and write EEPROM)
- 2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
- 金仓KFS数据双向同步场景部署
- Interface in TS
- Basic types of data in TS
猜你喜欢

C language series - Section 3 - functions

P35-P41 fourth_ context
![[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius](/img/01/c118725f74e39742df021b5dbcc33b.jpg)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius

Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching

vulnhub HA: Natraj

【刷题篇】接雨水(一维)
![[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification](/img/30/c840e28c0ef7c8ce574dcde4363863.jpg)
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
![[home push IMessage] software installation virtual host rental tothebuddy delay](/img/e7/eb20a773e4b674962f856d179a3769.jpg)
[home push IMessage] software installation virtual host rental tothebuddy delay

一名外包仔的2022年中总结

Mutex and rwmutex in golang
随机推荐
Leecode swipe questions and record LCP 18 breakfast combination
What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
服务器无法远程连接原因分析
Which code editor is easy to use? Code editing software recommendation
Social phobia of contemporary young people (III)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
[set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
How to connect WiFi with raspberry pie
[home push IMessage] software installation virtual host rental tothebuddy delay
Interface embedded in golang struct
Arduino application development - LCD display GIF dynamic diagram
xrandr修改分辨率与刷新率
因子选股-打分模型
Idea shortcut keys
Mutex and rwmutex in golang
The latest activation free version of Omni toolbox
GFS分布式文件系统(光是遇见已经很美好了)
[Yu Yue education] reference materials of political communication science of Communication University of China
js实现在可视区内,文字图片动画效果