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

你可能感兴趣的文章
nginx负载均衡的5种策略
查看>>
nginx负载均衡的5种策略(转载)
查看>>
nginx负载均衡的五种算法
查看>>
Nginx负载均衡详解
查看>>
Nginx负载均衡(upstream)
查看>>
Vue中删除el-table当前行的方法
查看>>
nginx转发端口时与导致websocket不生效
查看>>
Nginx运维与实战(一)-Nginx不同场景使用方法
查看>>
Nginx运维与实战(二)-Https配置
查看>>
Nginx部署_mysql代理_redis代理_phoenix代理_xxljob代理_websocket代理_Nacos代理_内网穿透代理_多系统转发---记录021_大数据工作笔记0181
查看>>
nginx部署本地项目如何让异地公网访问?服务器端口映射配置!
查看>>
Nginx配置HTTPS服务
查看>>
Nginx配置https的一个误区(导致404错误)
查看>>
Nginx配置Https证书
查看>>
Nginx配置http跳转https
查看>>
Nginx配置ssl实现https
查看>>
nginx配置ssl证书https解决公网ip可以访问但是域名不行的问题
查看>>
Nginx配置TCP代理指南
查看>>
NGINX配置TCP连接双向SSL
查看>>
Nginx配置——不记录指定文件类型日志
查看>>