![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
文章平均质量分 56
决定要好好毒树的Lucifer
这个作者很懒,什么都没留下…
展开
-
并查集:模板&例题
简述: 并查集(union find)是一种简单高效的数据结构,适用于解决元素分组的问题。并查集提供两种主要的操作:Union(合并两个集合)和Find(查找两个元素是否属于一个集合)。一般我们使用经过路径压缩和按大小合并这两种方式优化的并查集算法。 路径压缩指的是对于某个集合当中的所有元素,他们都具有一个共同而且直接的父元素,即这个集合的代表元素,而不需要递归向上搜索。代码实现的方法是:集合每加入一个元素,直接将其父元素设置为原集合的父元素即可(未考虑按大小合并)。 按大小合并指的是依照集合的大小决原创 2022-02-22 00:24:57 · 273 阅读 · 0 评论 -
LeetCode1631 - 最小体力消耗 (二分法BFS遍历、并查集)
题目: You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated(位于) in the top-left cell, (0, 0), and you hope to travel to th原创 2022-02-21 23:56:38 · 229 阅读 · 0 评论 -
LeetCode778 - 水位上升的泳池 (二分法BFS遍历、并查集)
题目: You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally ad原创 2022-02-15 18:14:26 · 226 阅读 · 0 评论