当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5176:The Experience of Love

题目描述
A girl named Gorwin and a boy named Vivin is a couple. They arrived at a country named LOVE. The country consisting of $N$ cities and only $N-1$ edges (just like a tree), every edge has a value means the distance of two cities. They select two cities to live,Gorwin living in a city and Vivin living in another. First date, Gorwin go to visit Vivin, she would write down the longest edge on this path(maxValue).Second date, Vivin go to Gorwin, he would write down the shortest edge on this path(minValue),then calculate the result of maxValue subtracts minValue as the experience of love, and then reselect two cities to live and calculate new experience of love, repeat again and again.

Please help them to calculate the sum of all experience of love after they have selected all cases.
输入解释
There will be about $5$ cases in the input file.
For each test case the first line is a integer $N$, Then follows $n-1$ lines, each line contains three integers $a$, $b$, and $c$, indicating there is a edge connects city $a$ and city $b$ with distance $c$.

[Technical Specification]
$1 < N <= 150000,1 <= a, b <= n,1 <= c <= {10}^{9}$
输出解释
For each case,the output should occupies exactly one line. The output format is Case #x: answer, here x is the data number, answer is the sum of experience of love.
输入样例
3
1 2 1
2 3 2
5
1 2 2
2 3 5
2 4 7
3 5 4
输出样例
Case #1: 1
Case #2: 17

提示
huge input,fast IO method is recommended.

In the first sample:
The maxValue is 1 and minValue is 1 when they select city 1 and city 2, the experience of love is 0.
The maxValue is 2 and minValue is 2 when they select city 2 and city 3, the experience of love is 0.
The maxValue is 2 and minValue is 1 when they select city 1 and city 3, the experience of love is 1.
so the sum of all experience is 1;
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 Valentine's Day Round

源链接: HDU-5176

最后修改于 2020-10-25T23:20:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 65536/65536K(Java/Others)