只有一个地方需要注意: 设节点a的根为u,b的跟为v,则:a = u + d[a]; b = v + d[b]; 已知:b-a=w.所以v - u = d[a] - d[b] + w; 在合并两个集合修改根节点时,把v的根改为u,同时v到根的距离为d[a] - d[b] + w; #include <cstdio> #include <cstring> ; int pa[MAXN]; long long int d[MAXN]; int findset( int x ) { if…
题目链接:https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e 题意:给出一个 n 个点 m 条边的无向图,每个点和每条边都有权值,让你删除一些边,使得最终的图中满足条件:一条边存在当且仅当包含该边的连通块的点权值和大于等于该边权值,问最少要移走多少条边. 题解:删边不好做,考虑加边,对于每条边,判断加入是否合法.按边权从小到大排序进行加边,要加入一条边之前,若之前两点不连通,则合并起来变成一个连通块,可以用并查集…
A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Me…
A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak…
Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf node L. Now given any weighted tre…