并查集
刷题
星空皓月
工欲善其事,必先利其器。
展开
-
LeetCode:952. 按公因数计算最大组件大小【欧拉筛 + 并查集】
返回图中最大连通组件的大小。原创 2022-07-30 23:53:23 · 111 阅读 · 0 评论 -
计蒜客 - T2026 -- 信息传递【求最小环长 :bfs + 并查集 or Trajan】
思路1:bfs + 并查集题意很简单,画个图就知道是求最小环长,利用并查集将v认u为父亲,最终在个集合里面的根节点都是起始结点。最后走一个bfs或者dfs就能跑出答案。AC代码#include<cstdio>#include<iostream>#include<vector>#include<queue>#include<cstring>#include<algorithm>using namespace std;原创 2020-08-17 22:18:37 · 262 阅读 · 0 评论 -
HDU - 3038 -- How Many Answers Are Wrong【带权并查集】
How Many Answers Are Wrong题意给定一段区间的和为x,问当前区间的和与前面的区间有没有冲突,如果有则是错误答案。最后输出错误答案数。eg:[1, 10] = 5[1, 3] = 2[4, 10] = 4很显然第三个区间就是错误的,因为[1,3]+[4,10] != [1,10].思路怎样判断当前区间与前面的区间形成冲突? 我们需要借助一个载体(根节点),记录左端点到其根节点的和与右端点到根节点的和,我们以集合的最左端为根节点,判断以下三种情况。1.l的根节点和r的原创 2020-07-30 23:33:45 · 1196 阅读 · 0 评论 -
POJ - 2492 -- A Bug‘s Life【种类并查集】
A Bug’s LifeDescriptionBackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individua原创 2020-07-20 23:01:09 · 327 阅读 · 0 评论 -
POJ - 1856 -- More is better 【并查集+简单离散化】
More is betterProblem DescriptionMr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected a room big enough to hold th原创 2020-07-20 22:53:02 · 159 阅读 · 0 评论