并查集
文章平均质量分 92
风去幽墨
当你为自己的未来踏踏实实地努力时,那些你从未见过的风景正一步步向你走来
展开
-
AtCoder Beginner Contest 214题解
D - Sum of Maximum Weights题意:给出一个树,包含n个节点,n-1条边,每条边有一个权重wi。记f(u,v)为点u到点v的最短路径上出现的最大的权重,求n个点两两之间的f(u,v)之和。题解:假设有两个树,两个树之间通过一个权重为w的边连接,且两个树中的边的权重都小于w,那么此时满足f(u,v)==w的点对个数就有size(tree1)*size(tree2) .根据上述假设,我们可以按照边权重大小重新加边来哦构造这颗树,在构造过程中就能够得知有多少个点对是满足f(u,v)原创 2021-08-15 10:13:15 · 330 阅读 · 0 评论 -
POJ-1611-The Suspects(并查集)
原题:Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is ...原创 2018-11-06 22:07:50 · 131 阅读 · 0 评论 -
POJ-2236-Wireless Network (并查集)
原题:An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in t...原创 2018-11-08 15:21:54 · 136 阅读 · 0 评论 -
POJ-2524-Ubiquitous Religions (并查集)
原题:There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university ...原创 2018-11-08 15:40:44 · 154 阅读 · 0 评论 -
POJ-1182 食物链 (并查集)&&并查集的深层次思想
题目链接:http://poj.org/problem?id=1182解题思路:这道题是并查集题目中的经典。。。而且比普通并查集提高了一个档次,下面在基础并查集的前提上讲解并查集的真正用法。基础回顾:find()函数找根结点的两种写法如下:第一种递归:int find(int x){ return x == pre[x] ? x : find(pre[x]);}第二种:i...转载 2018-11-08 21:29:37 · 129 阅读 · 0 评论 -
POJ-1182-食物链 (并查集)
原题链接:https://vjudge.net/contest/235901#problem/O动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说...原创 2018-11-12 16:51:39 · 176 阅读 · 0 评论 -
HDU-1116-Play on Words (并查集 +欧拉回路)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1116Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no...原创 2018-11-12 20:10:50 · 137 阅读 · 0 评论