博客
关于我
并查集(初学)
阅读量: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/

你可能感兴趣的文章
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
netty的HelloWorld演示
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty的网络框架差点让我一夜秃头,哭了
查看>>
Netty相关
查看>>
Netty简介
查看>>
Netty线程模型理解
查看>>
netty解决tcp粘包和拆包问题
查看>>
Netty速成:基础+入门+中级+高级+源码架构+行业应用
查看>>
Netty遇到TCP发送缓冲区满了 写半包操作该如何处理
查看>>
netty(1):NIO 基础之三大组件和ByteBuffer
查看>>
Netty:ChannelPipeline和ChannelHandler为什么会鬼混在一起?
查看>>
Netty:原理架构解析
查看>>