Disjoint-Set并查集
来源:互联网 发布:经济增长数据 编辑:程序博客网 时间:2024/05/17 08:58
路径压缩+启发式合并,应该是最快的了吧。
目前size数组还是有点小问题的,只能保证根节点所记录的该树的节点数是正确的,不过一般也只用这个,所以用的时候用size[root]就行,注意一下就可以,不影响使用
#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 100int set[maxn];int size[maxn];//结点数void init_set(){ for(int i=0;i<maxn;++i) { set[i]=i; size[i]=1; }}//路径压缩int findSet(int x){ if(x==set[x]) return x; else return set[x]=findSet(set[x]);}void unionSet(int x,int y)//启发式合并{ int fx=findSet(x); int fy=findSet(y); if(fy==fx) return; if(size[fx]>=size[fy]) { size[fx]+=size[fy]; set[fy]=fx; } else { size[fy]+=size[fx]; set[fx]=fy; }}int main(){}
0 0
- Disjoint-Set并查集
- 并查集(disjoint-set forests)
- 并查集 (Disjoint Set)
- 并查集(disjoint set)结构介绍
- Disjoint set(并查集) data structure
- 并查集(Disjoint Set)
- 并查集(Disjoint Set)
- disjoint set (union-find set) (并查集)
- 编程算法 - 并查集(disjoint set) 代码(C)
- 数据结构 之 并查集(Disjoint Set)
- 【算法导论-36】并查集(Disjoint Set)详解
- 并查集(disjoint set)的实现及应用
- 【Panoramic stitching】并查集(disjoint set)结构及源码
- 并查集-Disjoint Set 和 图-Graph
- 【数据结构】【计算机视觉】并查集(disjoint set)结构介绍
- 并查集(disjoint)
- 利用并查集(Disjoint Set)解决一道算法题
- 重学数据结构系列之——森林之并查集(Disjoint set)
- C++ 内存分布,编译与运行阶段探索?(暂时不确定标题)
- jedis 源码阅读三——PipeLine
- UVA 1363(p338)----Joseph's Problem
- 自学vim笔记
- ScaleDrawable的正确打开方式
- Disjoint-Set并查集
- 报告
- UVA 1368(p58)----DNA Consensus String
- Leetcode 160:Intersection of Two Linked Lists
- cpu运行模式切换以及异常处理
- math数学部分
- Heap和stack有什么区别?
- leetcode 5. Longest Palindromic Substring
- GenyMotion不能启动的问题,Unable to start the virtual device.VirtualBox cannot start the virtual device