当前位置:网站首页>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 .
边栏推荐
- Introduction to markdown grammar
- Swagger
- CTF PHP audit bypasses filtering learning from topics
- Development trend and prospect forecast report of China's financial industry 2022-2028 Edition
- Clickhouse stand alone installation
- Oracle 数据泵导表
- CTF serialization and deserialization
- mysql高级学习(跟着尚硅谷老师周阳学习)
- Notes on enterprise wechat development [original]
- Thymeleaf data echo, single selection backfill, drop-down backfill, time frame backfill
猜你喜欢

Nailing open platform - applet development practice (nailing applet client)

Clickhouse stand alone installation
![[Qunhui] this suite requires you to start PgSQL adapter service](/img/fb/1aea7eb833afc1a24531b612a98400.jpg)
[Qunhui] this suite requires you to start PgSQL adapter service

PHP small factory moves bricks for three years - interview series - my programming life
![[Qunhui] import certificate](/img/1f/ab63b0556a60b98388b482d70f6156.jpg)
[Qunhui] import certificate

一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)

Thinkphp6 implements a simple lottery system

CDN with OSS acceleration

Construction of art NFT trading platform | NFT mall

08_ Spingboot integrated redis
随机推荐
Using jsup to extract images from interfaces
Advanced learning of MySQL (learning from Shang Silicon Valley teacher Zhou Yang)
PHP installation SSH2 extension
2021/11/6-burpsuit packet capturing and web page source code modification
[H5 development] 01 take you to experience H5 development from a simple page ~ the whole page implementation process from static page to interface adjustment manual teaching
Understand CGI and fastcgi
Performance test comparison between PHP framework jsnpp and thinkphp6
TP5 distinct method paging problem
What are the advantages and risks of paper gold investment
Zeromq from getting started to mastering
Upload script file (one sentence back door) WAF bypass (PHP)
PHP syntax summary
redis集群的方式
SixTool-多功能多合一代挂助手源码
2022 talent strategic transformation under the development trend of digital economy
Development trend and prospect forecast report of China's financial industry 2022-2028 Edition
[Qunhui] this suite requires you to start PgSQL adapter service
08_ Spingboot integrated redis
[Qunhui] Internet access + custom port
"Eight hundred"