当前位置:网站首页>1.16 learning summary
1.16 learning summary
2022-06-26 04:34:00 【After all, I still walk alone】
I wrote one today And look up the title of the collection . It is also a simple understanding , The basic of union search set application . Personally, I think and search for , It's better to understand . This topic is described as follows .
This should be regarded as the template question of the parallel search set , I am here b Station to learn and search the set of When . I also use this type of questions to do Example . The core idea is still on the compressed path . With a recursion, all elements with the same ancestry , Put them in The tag As a common ancestor . The code is as follows
#include<stdio.h>
int n,m,q,f[10010],c,d,a,b;
int find(int x)
{
if(f[x]==x){
return x;}
else {
f[x]=find(f[x]);
return f[x];}
}
void hb(int x,int y)
{
f[find(x)]=find(y);
return ;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++){
f[i]=i;}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&c,&d);
hb(c,d);
}
for(int i=1;i<=q;i++)
{
scanf("%d%d",&a,&b);
if(find(a)==find(b))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
And the compressed path of the core The code is the next paragraph .
int find(int x)
{
if(f[x]==x){
return x;}
else {
f[x]=find(f[x]);
return f[x];}
}
Among them, this recursion is to integrate all common ancestors . All the values of the element are assigned to that ancestor, that is, the compression path .
Today's learning summary , That's it .
边栏推荐
- 一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)
- Sixtool- source code of multi-functional and all in one generation hanging assistant
- A brain map to summarize the needs analysis (a supplement to the actual situation at work)
- SixTool-多功能多合一代挂助手源码
- 防撤回测试记录
- Install Damon database
- Zhubo Huangyu: all the precious metals you want to know are here
- 1064 (42000) error occurred when installing MySQL and modifying root password
- "Eight hundred"
- PIP batch complete uninstall package
猜你喜欢
NPM installation tutorial
Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
Etcd watch principle
[Qunhui] import certificate
MySQL index details
Clickhouse stand alone installation
Zeromq from getting started to mastering
PIP batch complete uninstall package
CDN with OSS acceleration
Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
随机推荐
Install Damon database
Parse JSON interface and insert it into the database in batch
Your requirements could not be resolved
win10 系统打开的软件太小,如何变大(亲测有效)
Use shell script to analyze system CPU, memory and network throughput
mysql高级学习(跟着尚硅谷老师周阳学习)
MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
List of provinces, cities and counties in China
1064 (42000) error occurred when installing MySQL and modifying root password
问题随记 —— pip 换源
Implementation of seven classes of BlockingQueue interface
2020-12-18
Report on demand situation and development trend of China's OTC industry from 2022 to 2028
Understand CGI and fastcgi
条件查询
Tp6 controller does not exist: app\index\controller\index
numpy 索引及切片
Resolve PHP is not an internal or external command
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Principle and implementation of syn cookie