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

建议使用的浏览器:

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

5886:Tower Defence

题目描述
There was a civil war between two factions in Skyrim, a province of the Empire on the continent of Tamriel. The Stormcloaks, led by Ulfric Stormcloak, are made up of Skyrim's native Nord race. Their goal is an independent Skyrim free from Imperial interference. The Imperial Legion, led by General Tullius, is the military of the Empire that opposes the Stormcloaks and seeks to reunite and pacify the province.

The current target of General Tullius is to defend Whiterun City. Near by this city there are $N$ towers under the Empire's control. There are $N - 1$ roads link these tower, so solders can move from any tower to another one through these roads.

In military affairs, tactical depth means the longest path between two towers of all. Larger the tactical depth is, more stable these towers are.

According to the message sent by spies, General Tullius believe that Stormcloaks is planning to attack one of these roads, and his towers would be divided into two parts. However, Tullius does not know which one, so he supposes the possibility that Stormcloaks attack these roads are the same. Now, General Tullius ask for your help, to calculate the expectation of tactical depth after this attack.

To avoid the issue of precision, you need to calculate $expectation \quad of \quad tactical \quad depth \times (N - 1)$.
输入解释
The first line of input contains an integer $t$, the number of test cases. $t$ test cases follow.
For each test case, in the first line there is an integer $N(N \leq 100000)$.
The $i$-th line of the next $N-1$ lines describes the $i$-th edge. Three integers $u,v,w~(0 \leq w \leq 1000)$ describe an edge between $u$ and $v$ of length $w$.
输出解释
For each test cases, output $expectation \quad of \quad tactical \quad depth \times (N - 1)$.
输入样例
2
3
2 1 2
3 2 5
5
2 1 7
3 1 7
4 2 5
5 2 6
输出样例
7
63
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5886

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

共提交 0

通过率 --%
时间上限 内存上限
3000/1000MS(Java/Others) 32768/32768K(Java/Others)