博客
关于我
并查集(初学)
阅读量:334 次
发布时间:2019-03-04

本文共 496 字,大约阅读时间需要 1 分钟。

今天看了并查集的具体内容吧 首先先创建俩个函数 一个用来存 一个用来查 。并查集就是看用来看图中有几个小的联通区域

还有个路径缩短法 就是把具有联通在一起的节点 都设置一个 父亲节点

int pre[n]/存放父类节点
int find(int root){    int son=root;   while(root!=pre[root])//查找上级        root=pre[root]; return  root; //返回上级;}
int jion(int start,int finish) {  int root1=find(start);   int root2= find(finish);    if(root1!=root2)    //如果父类节点不相同(既构成不了环路)  把所产生的 父类节点存进去       pre[root1]=root2;}
while(son!=root)  //路径压缩{   int cmp=pre[son];    pre[son]=root; // 把上级节点 赋值为 最上级的节点 也就是赋值根节点  son =cmp;}

转载地址:http://xxqq.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>