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

建议使用的浏览器:

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

7187:Slipper

题目描述
Gi is a naughty child. He often does some strange things. Therefore, his father decides to play a game with him.

Gi's father is a senior magician, he teleports Gi and Gi's Slipper into a labyrinth. To simplify this problem, we regard the labyrinth as a tree with $n$ nodes, rooted at node $1$. Gi is initially at node $s$, and his slipper is at node $t$. In the tree, going through any edge between two nodes costs $w$ unit of power.

Gi is also a little magician! He can use his magic to teleport to any other node, if the depth difference between these two nodes equals to $k$. That is, if two nodes $u,v$ satisfying that $|dep_u-dep_v|=k$, then Gi can teleport from $u$ to $v$ or from $v$ to $u$. But each time when he uses magic he needs to consume $p$ unit of power. Note that he can use his magic any times.

Gi want to take his slipper with minimum unit of power.
输入解释
Each test contains multiple test cases. The first line contains the number of test cases $(1 \le T \le 5)$. Description of the test cases follows.

The first line contains an integer $n$ --- The number of nodes in the tree. $2 \leq n \leq 10^6 $.

The following $n-1$ lines contains 3 integers $u,v,w$ that means there is an edge between nodes $u$ and $v$. Going through this edge costs $w$ unit of power. $1 \leq u,v \leq n,1 \leq w \leq 10^6$.

The next line will contain two separated integers $k, p$. $1 \leq k \leq \max_{u\subseteq V} \left( dep_u \right),0 \leq p \leq 10^6$.

The last line contains two positive integers $s,t$, denoting the positions of Gi and slipper. $1 \leq s \leq n,1 \leq t \leq n$. It is guaranteed the $s \ne t$.
输出解释
For each test case:

Print an integer in a line --- the minimum unit of power Gi needs.
输入样例
1
6
6 1 2
3 5 2
2 4 6
5 2 2
5 6 20
3 8
6 5
输出样例
12
来自杭电HDUOJ的附加信息
Hint Example1: Gi can go from node 6 to node 1 using 2 units of power. Then he teleports from node 1 to node 2 using 8 units of power. Finally, he goes from node 2 to node 5 using 2 units of power. $Total\ cost = 2+8+2 = 12$

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

源链接: HDU-7187

最后修改于 2022-09-15T06:17:14+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 524288/262144K(Java/Others)