【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)
来源:互联网 发布:软件协议 编辑:程序博客网 时间:2024/06/04 18:14
+++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++
- /* father[x]表示x的父节点 */
- int father[MAX];
- /* rank[x]表示x的秩 */
- int rank[MAX];
- /* 初始化集合 */
- void Make_Set(int x)
- {
- father[x] = x;
- rank[x] = 0;
- }
- /* 查找x元素所在的集合,回溯时压缩路径 */
- int Find_Set(int x)
- {
- if (x != father[x])
- {
- father[x] = Find_Set(father[x]);
- }
- return father[x];
- }
- /* 按秩合并x,y所在的集合 */
- void Union(int x, int y)
- {
- x = Find_Set(x);
- y = Find_Set(y);
- if (x == y) return;
- if (rank[x] > rank[y])
- {
- father[y] = x;
- }
- else
- {
- if (rank[x] == rank[y])
- {
- rank[y]++;
- }
- father[x] = y;
- }
- }
+++++++++++++++++++++++++++++++++++++++
相关题目
并查集的基础应用:
POJ 1611 The Suspects C语言版
POJ 2524 Ubiquitous Religions C语言版
POJ 1182 食物链 C语言版
最小生成树Kruskal算法并查集应用:
POJ 1258 Agri-Net C语言版 Kruskal
POJ 1251 Jungle Roads C++版 Kruskal
POJ 1861 Network C语言版 Kruskal
文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。
0 0
- 【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)
- 【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)
- 不相交集合 - 并查集
- 并查集(不相交集合)
- 不相交集合 - 并查集
- 并查集(不相交集合)
- 不相交集合(并查集)
- 不相交集合-并查集
- 并查集(不相交集合)基础知识详解
- 用于不相交集合的数据结构(并查集)
- 不相交集合的数据结构-并查集
- 并查集(不相交集)
- 不相交集(并查集)(C++)
- 不相交集(并查集)
- 并查集及其链表与不相交集合森林实现
- 实用算法实现-第12篇不相交集合(并查集)
- [算法导论读书笔记]用于不相交集合的数据结构(并查集)
- 【算法与数据结构】不相交集合——并查集
- #include<string>与#include<string.h>的区别
- 杭电 3177 Crixalis's Equipment
- 在Ubuntu系统上进行SAE+Python+Django开发记录—1.环境搭建
- Android Application
- 定时ajax抓取数据
- 【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)
- 详解Spring中的CharacterEncodingFilter--forceEncoding为true在java代码中设置失效--html设置编码无效?不知真假
- SVD解线性方程组——秘密大起底
- String、StringBuffer与StringBuilder之间区别
- A*算法
- [leetcode] Scramble String
- B. Suffix Structures
- C++中#include<string>的问题
- archlinux的wiki非常强大