并查集实现:普通算法、稚压缩、压缩路径。 Linux下查并集运行结果。 ---------Please Select you choice:---------- 1 Enter the relation! 2 Find its root! 3 Find its relations! 0 Quite! Your choice is :3 Please enter the number you want to know : 1 8 YES,1 and 8 have the same root!
并查集与最小生成树 原理讲解、c++代码。
并查集是⼀一种树型的数据结构,⽤用于处理理⼀一些不不相交集合的合并及查询问题。
一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边。最小生成树可以用kruskal(克鲁斯卡尔)算法或prim(普里姆)算法求出。