当前位置:网站首页>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;
}
边栏推荐
- 用户体验五要素
- Basic types of data in TS
- "Final review" 16/32-bit microprocessor (8086) basic register
- JMeter starts from zero (III) -- simple use of regular expressions
- Supervised pre training! Another exploration of text generation!
- 有监督预训练!文本生成又一探索!
- Idea shortcut keys
- [fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
- How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
- The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
猜你喜欢
Application of I2C protocol of STM32F103 (read and write EEPROM)
Nodejs Foundation: shallow chat URL and querystring module
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found
vulnhub HA: Natraj
BMZCTF simple_ pop
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
有监督预训练!文本生成又一探索!
[graduation season · aggressive technology Er] Confessions of workers
js实现在可视区内,文字图片动画效果
随机推荐
金仓数据库KingbaseES 插件kdb_date_function
Basic types of data in TS
JS native common knowledge
树莓派如何连接WiFi
The latest activation free version of Omni toolbox
[no title] 2022 chlorination process examination content and free chlorination process examination questions
China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
Five elements of user experience
MongoDB 慢查询语句优化分析策略
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
[brush questions] find the number pair distance with the smallest K
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
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 =
Database management tool, querious direct download
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
[fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
[brush questions] most elements (super water king problem)
[brush questions] connected with rainwater (one dimension)
eth入门之DAPP
Social phobia of contemporary young people (II)