[ICPC2018 WF] Conquer The World

题意翻译

给定一个 $n$ 点 $n-1$ 边的无向图,每条边 $(u,v)$ 有边权 $c$。 现在第 $i$ 个点有 $x_i$ 的点权,每个点需要 $y_i$ 的点权,所以你可以移动点权到不同的点上。移动一条边上的点 $u$ 的 $k$ 个单位点权到 $v$ 要用 $k \times c$ 的代价。 求满足所有点的需要的最小代价。 $1 \le n \le 2.5 \times 10^5$,$1 \le u,v \le n$,$1 \le c \le 10^6$,$0 \le \sum y_i\le \sum x_i \le 10^6$。 翻译者:一只书虫仔

题目描述

Bwahahahahaha!!! Your nemesis, the dashingly handsome spy Waco Powers, has at last fallen to your secret volcano base's deathtraps (or so you assume, being a little too busy to witness it firsthand). At long last, you are all set to CONQUER THE WORLD! Nothing will stand in your way! Well, nothing except a minor problem of logistics. Your evil armies have announced that they will not continue carving their relentless path of destruction across the puny nations of the world without being paid. And unfortunately you are running low on cash $-$ a volcano lair has many wonderful qualities, but `reasonably affordable` is not one of them. You have had to pull funds from the travel budget to pay your ungrateful underlings. Now you are not sure how you will actually get your armies into position to CONQUER THE WORLD. You have a map of the nations of the world and all your available transport routes between them. Each route connects two nations and has a fixed cost per army that uses it. The routes are laid out such that there is exactly one way to travel between any two nations. You know the current position of each of your armies and how many you will need to place permanently in each nation in order to subjugate it. How can you move the armies into place as cheaply as possible so you can CONQUER THE WORLD?

输入输出格式

输入格式


The first line of input contains an integer $n (1 \le n \le 250 000)$ , the number of nations. This is followed by $n − 1$ lines, each containing three integers $u , v$ , and $c (1 \le u , v \le n , 1 \le c \le 10^{6}),$ indicating that there is a bidirectional route connecting nations $u$ and $v$ , which costs $c$ per army to use. Finally, another $n$ lines follow, the $i^{th}$ of which contains two non-negative integers $x_{i}$ and $y_{i},$ indicating that there are currently $x_{i}$ armies in nation $i$ , and you need at least $y_{i}$ armies to end up in that nation in the final configuration. The total number of armies (the sum of the $x_{i}$ values) is at least the sum of the $y_{i}$ values, and no more than $10^{6}.$

输出格式


Display the minimum cost to move your armies such that there are at least $y_{i}$ armies in nation $i$ for all $i$ .

输入输出样例

输入样例 #1

3
1 2 5
3 1 5
2 1
5 0
1 3

输出样例 #1

15

输入样例 #2

6
1 2 2
1 3 5
1 4 1
2 5 5
2 6 1
0 0
1 0
2 1
2 1
0 1
0 1

输出样例 #2

9

说明

Time limit: 8 s, Memory limit: 1024 MB.