当前位置:网站首页>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;
}边栏推荐
- 服务器无法远程连接原因分析
- x Problem B
- Appium automated testing framework
- [NLP]—sparse neural network最新工作简述
- MySQL field userid comma separated save by userid query
- GFS分布式文件系统(光是遇见已经很美好了)
- The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
- [fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
- [pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
- Export of zip file
猜你喜欢
![[NLP]—sparse neural network最新工作简述](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[NLP]—sparse neural network最新工作简述

MPLS setup experiment

Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
![[brush questions] most elements (super water king problem)](/img/79/13a715b74bc18a4a62113de76a65f6.png)
[brush questions] most elements (super water king problem)
![[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

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

Two points -leetcode-540 A single element in an ordered array
![[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN

Application of I2C protocol of STM32F103 (read and write EEPROM)

Feature_selection
随机推荐
[fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
因子选股-打分模型
Xrandr modify resolution and refresh rate
树莓派如何连接WiFi
【刷题篇】 找出第 K 小的数对距离
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
『期末复习』16/32位微处理器(8086)基本寄存器
Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
arthas watch 抓取入参的某个字段/属性
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
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 =
[set theory] set concept and relationship (set family | set family examples | multiple sets)
Kubernetes源码分析(一)
MySQL field userid comma separated save by userid query
[Yu Yue education] reference materials of political communication science of Communication University of China
mysql字段userid逗号分开保存按userid查询
x Problem B
Application of I2C protocol of STM32F103 (read and write EEPROM)
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来