当前位置:网站首页>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 .
边栏推荐
- Mutex of thread synchronization (mutex)
- Jenkins introduces custom jars
- [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
- Laravel framework Alipay payment fails to receive asynchronous callback request [original]
- CTF crypto (I) some simple encoding and encryption
- PHP design function getmaxstr to find the longest symmetric string in a string - [original]
- Zhimeng CMS will file a lawsuit against infringing websites
- 08_ Spingboot integrated redis
- A brain map to summarize the needs analysis (a supplement to the actual situation at work)
- Tp6 is easy to tread [original]
猜你喜欢

OSS CDN alicloud configuration method
![[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface](/img/37/84b7d59818e854dac71d6f06700cde.jpg)
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface

Tp6 multi table Association (table a is associated with table B, table B is associated with table C, and table d)

Threejs special sky box materials, five kinds of sky box materials are downloaded for free
![Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]](/img/64/c3bb27a3711a6f0cc7b281d1a961af.jpg)
Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]

35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling

微软禁止俄用户下载安装Win10/11

Clickhouse stand alone installation

Computer network high frequency interview questions

Double buffer technology asynchronous log system
随机推荐
A troubleshooting of website crash due to high CPU
C generic
Using jsup to extract images from interfaces
08_SpingBoot 集成Redis
Mutex of thread synchronization (mutex)
A brain map to summarize the needs analysis (a supplement to the actual situation at work)
Install dbeaver and connect Clickhouse
TP5 distinct method paging problem
Simple use of redis in laravel
CTF serialization and deserialization
Introduction to markdown grammar
Install Damon database
Parse JSON interface and insert it into the database in batch
Motivational skills for achieving goals
微软禁止俄用户下载安装Win10/11
Tips for using idea
企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?
条件查询
Gateway can not connect to tcp://127.0.0.1: Connection refused
Report on operation mode and future development trend of China's refining and chemical market 2022-2028