并查集(Union/Find)模板及详解
概念:
并查集是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题。一些常见的用途有求连通子图、求最小生成树的Kruskal 算法和求最近公共祖先等。
操作:
并查集的基本操作有两个:
Union(x, y):把元素x 和元素y 所在的集合合并,要求x 和y 所在的集合不相交,如果相交则不合并。
Find(x):找到元素x 所在的集合的代表,该操作也可以用于判断两个元素是否位于同一个集合,只要将它们各自的代表比较一下就可以了。
实现:
并查集的实现原理也比较简单,就是使用树来表示集合,树的每个节点就表示集合中的一个元素,树根对应的元素就是该集合的代表,如下图所示。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANIAAAC1CAIAAAClCjb3AAAg7klEQVR4nO1da1AV1x3fziRTki+STmugcUDiRKtWxKbRagVKFBxFUAgiREFaXolGyFAUogjKKwUtDSjO8HAqIGmroBGoGR5WeaiJlEQhygSnCowJ4jQj94vCp/bHHrNu9l4uu2cf3L13fx+Yvcvd8997zu//OnvOf5/73//+xxgwoC2em+kbUAUTExN1dXVDLAYHB7nzc+fO9fHx8fb2dnNzm7m70yW6u7tbW1tx0N7ezp10cnLy9fVFf77xxhuSWrM32rW1tZ05c6a+vv6tt95yd3cHyaKiorj/goUdHR2HDh1atmxZamqq1M5yQAwPD0OBT548+dJLL61btw5nDhw4wP13fHy8s7MTPXn37t309PS4uLgf//jHYpq1H9qBcCkpKR4eHuHh4SUlJRZ//+rVq7dt24aDpqYmdBaUFZ2Ik5rfrA5gMpn27t176dKlyMhIMG/+/PkWv7Z27Vr8HR0dLSoqWrJkyTvvvBMbGztr1izrjdsD7UgHPXjwwErvCLCRRVdXV05ODj5WV1e//PLLKt+mnlBbW1tQUJCWllZWVibm++g9fB9qf/z4cfiQrKwsot5TQfe0g5HbuXPntL/TImDnmpubQb6goKATJ05AWdW4Q30BYXF0dLSzszMiOamqiO8jgAH5YAV6e3tBxKm+qW/agXMVFRWIdqe16lYA8jU2NsI1JyUlISJU8PZ0B/iNhIQERMNwBdSNYCx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Q0WAQJU1dcXMxfNP9suhicSE1NbW5uVkk2OP3ZZ5+B3Cq1b4AOGqz6RuMQYXkvxerVq11cXOrr61VytRkZGQcOHDBMnQ0CBg+5RVhYmBoTW4isqqqqGhsb+Sd/8HCsvLw8ICBg/vz5irvarKwsX19foySKbQJsKy0tjY6ORrKprF2Ae0WzaFxA6B/QDiKRWCDLRb6pIPFhQQcHB6UW1DCgJd54443du3eDIvJLAvCBBtGs+dpK4VIANze3Y8eOweQq9X56tAMdsvhaAQM2BaSVQ0NDW7dura6ulm/ziJ0LDg62WIDHwgoUsK2uri4+Ph48tVK0RwyQt+KvUYZCLyA1axBoyXR3iOfCw8P37NkzFX8sL3yCzYPghIQE+NzDhw9TLE4hxaoSExONMgD6AogC5pFpZLBQqtmDkUMkd/LkydraWivecsr1dqRoD9iDPMDPz++Pf/yjyOqwuARMRVKslJs2oDEwap2dnUVFRTiAv9q+fbuYPQ8mk+nUqVPFxcWRkZG43Pol0yzzJIXywFxSHXb9+vUI+xAhCpRgeHi4t7cXSTKyhzVr1hw5csTYoaNrgDSHDh3auXMnyDdv3rzf/va3iNI8PT3Nh7W7uxtDj/D9ypUr8GwgnBjvLGp18TYWAwMDra2tOTk5XV1djx8/njNnzqJFi1paWhh2/cyyZctwZ4WFhUYdO7sBCFTAoq2tDTYFqQapkU2cWF9fH8MuX/Ly8kIaICmCl7CofT4Lbi4bYeOdO3fUe6phwHawlgX3EQaIYflA3eD/ATSdxRwyRTxwAAAAAElFTkSuQmCC" alt="" name="图像1" width="210" height="181" align="bottom" border="0" />
图中有两棵树,分别对应两个集合,其中第一个集合为 {a,b,c,d},代表元素是 a;第二个集合为 {e,f,g},代表元素是 e。
树的节点表示集合中的元素,指针表示指向父节点的指针,根节点的指针指向自己,表示其没有父节点。沿着每个节点的父节点不断向上查找,最终就可以找到该树的根节点,即该集合的代表元素。
假设使用一个足够长的数组来存储树节点(很类似之前讲到的静态链表),即父节点是其自身:
aaarticlea/png;base64,iVBORw0KGgoAAAAN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PAnSTuYze0jISIclsHI0tLSp556yhs9vPTrr7++9dZb+/Xrh5EKqxym8KALWIaoKSoqevvtt8Xokci9MCe0MXL16tXKCVuLgDzc48L7E6PxgBsVJ23hfhfenyI536g4aQti1r0/iXCm9kbFSVSQdR514b0jNse4UXESFQza4y68dwhsHDIwYesHjNgMF+JPoR8h0MCErR8ws0+7EH8S1/jkgQMHTB3/fwFWYP1/17mdKgAAAABJRU5ErkJggg==" alt="" name="图像2" width="384" height="67" align="bottom" border="0" />
接下来,就是find 操作了,如果每次都沿着父节点向上查找,那时间复杂度就是树的高度,完全不可能达到常数级。这里需要应用一种非常简单而有效的策略——路径压缩。
优化:
路径压缩,就是在每次查找时,令查找路径上的每个节点都直接指向根节点,如图所示。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjUAAADtCAIAAADIhROkAAAx10lEQVR4nO2dfVBTV/rH05ntgJ2dAdcZhdYBsaNrnUGtLbZ2wdYKWGsAEUp1EepuBNsCspOiWBSUF+0iyAwqzgpkVl6sEqGtENsKuG4B2y6prZodt8JslYwKcdet2T+UzOyOv+eXu03TJIT7bl6+nz+Y5Cb3nEtycz7nOa8/e/DggQIAAADwMH72sC8AeDRms7m9vd1kMo2MjFy/ft12fN68ecuWLYuOjp4xY8bDuzoAgC8DPwHX9Pb2trS0/OlPf1q7di1JiGyUkZFhe/Xq1audnZ2/+93vXnjhhZ07d0ZGRj7ESwUA+CTwE3CEzKRWqyMiIjIzM+vr6wMCApzfQ5GTSqWiBzqdjh7Qm/Py8uig7BcLAPBZ4CfwI2azedu2bWNjY+3t7XPnzmVzitIKWaq8vJyearXaoKAgiS8TAOAXwE/gf1DY9Pbbb+/atSs9PZ3ruYylBgYG4uLiNBoNmvsAAMKBn8D/Q3JqaGjQ6/VCop/o6GgKvLKysvLy8khXIl4eAMAPgZ/A/+TU3NzssquJE2FhYVqtNjs7e2RkJCcnR5TLAwD4J/CTv9PR0UFGEUVODBSBtbW1bd68ua6uDooCAPAGfvJrh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Fs/WQjyortqdFoNJvNUkzmBQAA4M/8H+mjEWpIYYXwAAAAAElFTkSuQmCC" alt="" name="图像3" width="565" height="237" align="bottom" border="0" />
最后是合并操作Union,并查集的合并也非常简单,就是将一个集合的树根指向另一个集合的树根,如图所示。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhIAAADtCAIAAABlBAsNAAA7/ElEQVR4nO2de1BUV57HO1vZCUltFbpTJZhxQTIrRrd85KEpR9GYIJYOoGgHMQKyBYKlIikETfCBgDKLEqrQkBqRnhpeq2CjI/RkSrqzDo8kEzpmRtjRiDsRu3QUt1zp2lqlZ7cq+7VP5qbTNG3f2/ce+vb9ff6wmrb7ntvn/r7n+/ud+zhPf/PNN7ogxeFwWK3W0dHRvr4+/BkWFjZz5sw5c+aEhoZO9K6pFbvdPjAwMDIy0t/fjz8jnVCXEkpAwRawPD3ROyA/g4ODzc3Np06dun379pIlS0JCQl577TW8j+BrbW29dOnS888/n5KSsn37doo/H0GXGgyGf/3Xf3306NErr7wyadKkefPm4f3u7u6hoSF06QsvvLB27VrqUsJ/KNgCn6CyDYvFUlRUhPIiIyMDryMiIjx+DHFpNBoXLFiwcePGbdu2oQrhvJ8qoq2traSkBC9ycnK++OKL8foKWWFHRwe6FD1PeiakQcGmFoLENoaHh7Ozs/ECeQrKWO8fjo6Ohrsg4PDhmJiYpKQk/EnB54bNZsvNzUWuB4tFj3n/8Bwn6NKamhqm5127dj3zzDN8dpVQO0y/FGxqIRhso7m5uaKioqqqKjY21vdvwSfy8/MRfHV1dYmJiY2NjeNVJxoEnfnLX/5SQpcyP4ae4+LiWltbqZIjnohk/VKwTRSqt43i4uK7d+/29PRIKxeQpCDyVqxYodfrWfIi+x6qjpycnPDwcKvVKi2DY3pOcOJL8UdoGT/1S8E2IajbNjDAzZw5k82H+gPqYrPZnJycnJ6evmnTJln2TY04HI6dO3cuXbrU/06AgDs6OtCl2OD69etl2T0iyJBLvxRsnFGrbcg4wDGQtrS3t2ObN2/eRP4i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II=" alt="" name="图像4" width="530" height="237" align="bottom" border="0" />
这里也可以应用一个简单的启发式策略——按秩合并。该方法使用秩来表示树高度的上界,在合并时,总是将具有较小秩的树根指向具有较大秩的树根。简单的说,就是总是将比较矮的树作为子树,添加到较高的树中。为了保存秩,需要额外使用一个与uset 同长度的数组,并将所有元素都初始化为0。(不常用,可以与路径压缩一起写)
模板:
#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int pre[];
int rank[];
int Find(int x)//使用递归写find函数,同时有路径压缩
{ /*if(x!=pre[x])//递归查找前导点
{
pre[x]=find(pre[x]);
}
return pre[x];*/
int a;
a=x;
while(pre[a]!=a)///循环方法查找前导点
{
a=pre[a];
}
int i=x,j;
while(i!=a)///路径压缩
{
j=pre[i];///记录x的前导结点
pre[i]=a;///将i的前导结点设置为r的根节点.
i=j;
}
return a; }
void Union(int x,int y)
{
int a,b;
a=Find(x);///x的根节点为a
b=Find(y);///y的根节点为b
if(a!=b)///如果a,b不是相同的根节点,则说明ab不是连通的
{
pre[a]=b;///将a,b连接,将a的前导点设置为b
}
}
int main()
{
int m,n;
while()
{
cin>>n;
if(n==) break;
cin>>m;
for(int i=; i<=n; i++)//初始化数组
{
pre[i]=i;
rank[i]=;
}
int x,y;
for(int i=; i<m; i++)
{
cin>>x>>y;
Union(x,y);
}
int sum=;
for(int i=; i<=n; i++)
{
if(pre[i]==i)
sum++;
}
cout<<sum-<<endl;
}
return ;
}
并查集(Union/Find)模板及详解的更多相关文章
- 【转】Eclipse Java注释模板设置详解
Eclipse Java注释模板设置详解 设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后 ...
- 【转载】 Eclipse注释模板设置详解
Eclipse注释模板设置详解 网站推荐: 金丝燕网(主要内容是 Java 相关) 木秀林网(主要内容是消息队列)
- mongo 3.4分片集群系列之六:详解配置数据库
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...
- mongo 3.4分片集群系列之五:详解平衡器
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...
- SQLAlchemy02 /SQLAlchemy对数据的增删改查操作、属性常用数据类型详解
SQLAlchemy02 /SQLAlchemy对数据的增删改查操作.属性常用数据类型详解 目录 SQLAlchemy02 /SQLAlchemy对数据的增删改查操作.属性常用数据类型详解 1.用se ...
- SQLAlchemy(二):SQLAlchemy对数据的增删改查操作、属性常用数据类型详解
SQLAlchemy02 /SQLAlchemy对数据的增删改查操作.属性常用数据类型详解 目录 SQLAlchemy02 /SQLAlchemy对数据的增删改查操作.属性常用数据类型详解 1.用se ...
- POJ-1182 食物链---并查集(附模板)
题目链接: https://vjudge.net/problem/POJ-1182 题目大意: 中文题,不多说. 思路: 给每个动物创建3个元素,i-A, i-B, i-C i-x表示i属于种类x,并 ...
- 并查集 P3367 【模板】并查集
P3367 [模板]并查集 #include<iostream> #include<algorithm> #include<cstdio> #include< ...
- 并查集---体会以及模板&&How Many Tables - HDU 1213
定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己 ...
随机推荐
- 关于Hibernate的部分知识总结
[部分内容参考地址:https://www.cnblogs.com/woniu2219/p/7111857.html] Hibernate Hibernate是一个开放源代码的对象关系映射框架,它对J ...
- 【读书笔记 - Effective Java】01. 考虑用静态工厂方法代替构造器
获取类的实例有两种方法: 1. 提供一个公有的构造器(最常用). 2. 提供一个公有的静态工厂方法(static factory method). // 静态工厂方法示例 public static ...
- 如何在tornado中以异步的方式调用同步函数
问题 如何在tornado的coroutine中调用同步阻塞的函数 解决方案 使用python内置标准库的concurrent.futures.ThreadPoolExecutor和tornado.c ...
- 抓包之Charles For Mac 4.0+破解版
前言:突然间发现好久没有写博客了,最近被公司的项目弄得脑壳疼
- Java中常见的比较
一.StringBuffer.StringBuilder.String 1) 都是 final 类, 都不允许被继承; 2) String 长度是不可变的, StringBuffer.StringBu ...
- C# 发送Http协议 模拟 Post Get请求
1.参数 paramsValue的格式 要和 Reques.ContentType一致, 如果 contentype "application/x-www-form-urlencoded& ...
- 如何快速生成数据库字典(thinkphp5.0)
本教程将教你快速生成数据库字典 示例代码使用PHP框架:Thinkphp5.0 PHP代码: /** * 生成数据库字典html * 可直接另存为再copy到word文档中使用 * * @return ...
- sea.js模块化工具
sea.js 一. sea.js向全局中引入了两个变量seajs.define: 1.seajs用加载文件 seajs.use(deps,callback)异步引入入口模块 路径要以sea.js文件所 ...
- select epoll poll
如何理解 Epoll select 和 poll 三种模型,能否用生活中的例子做比喻? 比如说你从某宝下单买了几个东西,这几个东西分别由N个快递员分别给你送过来.在某一时刻,你开始等快递.对于sele ...
- #if、#if defined 的使用
#if的使用 if 后面接的是表达式 #if a==1 code -- #endif 如果#if后面的表达式能成立,就会把#if和#endif之间的代码编译进去 #if defined的使用 #if ...