并查集
天涯-沧海
acmer
展开
-
(并查集)CodeForces 1245D Shichikuji and Power Grid
先每个点连边,边值为(k[i]+k[j])*(abs(b[i].x-b[j].x)+abs(b[i].y-b[j].y)),然后设一个虚点0和每个点连边,边值为c[i],然后跑并查集就好了 Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows: There are n new cities located in Prefecture X. Cities..原创 2020-06-25 14:42:10 · 226 阅读 · 0 评论 -
(并查集)Two Fairs CodeForces - 1276B
这题我一开始想的是缩点,然后a子树去掉有b的子树后假设有x个点,b同理有y个点,x*y就是答案,但是有点难写,我记得去年这场cf打的时候我口胡过一个做法,但现在不太记得去了,就去翻了一下,发现我当时的想法真的好,再看我刚才想的算法,惭愧惭愧 这就是我去年的做法,真的妙多了,删掉和ab相连的边,然后用并查集处理下联通块就好了 There are n cities in Berland and some pairs of them are connected by two-way roads...原创 2020-06-02 01:22:02 · 182 阅读 · 0 评论 -
The Suspects
Description 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 str...原创 2019-04-17 21:24:21 · 147 阅读 · 0 评论 -
HDU - 1863 畅通工程
#include <iostream> #include<stdio.h> #include<algorithm> using namespace std; typedef struct Dt { int x,y,sum; }Dt; Dt a[120]; int q[120]; bool cmp(Dt x,Dt y) { return x.su...原创 2019-04-23 17:43:40 · 77 阅读 · 0 评论 -
(并查集)CFGym 102299G Hunting leshys
题意:n个人,m个操作,每个人有一个权值p,操作1:给你i和j,i成为j上级,操作2:询问第i到他根节点间最小的数是多少 思路:并查集,这题由于每个人最多一个上级,直接让j的父亲是i,然后从i一直找父亲,更新最小值就好了 #include<stdio.h> #include<algorithm> using namespace std; #define maxn 15...原创 2019-10-04 21:33:09 · 265 阅读 · 0 评论