#P10838. 『FLA - I』庭中有奇树

    ID: 10318 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论贪心二分洛谷原创O2优化树论洛谷月赛

『FLA - I』庭中有奇树

Description

In the game, Glz is given an unrooted tree with nn nodes, with a starting node SS and a destination node TT. Each of the edges has an integer weight.

There is a piece that can be moved between nodes along the edges, with each move costing a number of coins equal to the weight of the edge it passes through.

That is, if there exists an edge connecting nodes xx and yy with an edge of weight ww, then Glz can choose to move the piece from xx to yy, paying ww coins. At the beginning of the game the piece is at node SS. Glz needs to make the piece at node TT eventually after some moves.

Since Glz was once told that playing a game without using a plug-in is the same as not playing, Glz decides to use a plug-in. Using this plug-in he can spend kk coins on moving a piece from the current node to any node not adjacent to the current node. However, Glz can only use this plug-in at most once.

The righteous Ycy cannot sit idly by. Before Glz makes his move, Ycy can block up to mm possible teleportation routes. If Ycy blocks the teleportation route from node xx to node yy, the number of coins that it takes for Glz to teleport a piece from node xx to node yy becomes exactly 10910^9 coins. Due to the power of the plug-in, Glz knows which routes Ycy has blocked after his moving process begins. Note that the blocking procedure is unidirectional, that is, blocking the teleportation route from node xx to node yy does not affect Glz's teleportation from node yy to node xx.

Interestingly, during the game, Glz wants to minimize the number of coins spent, while Ycy is trying to maximize the number of coins spent.

If both of them adopt their optimal strategy, how many coins will Glz spend in total?

Input Format

The first line of input contains five integers nn, mm, kk, SS and TT — the number of nodes on the tree, the maximum teleportation routes that can be blocked, the coins that using the plug-in costs, the index of the starting node and the index of the destination node.

Then n1n - 1 lines follow, each line contains three integers uiu_i, viv_i, wiw_i, representing an edge on the tree connecting nodes uiu_i and viv_i, with a weight of wiw_i.

Output Format

Output a single line containing an integer, which denotes the coins that Glz would spend, in the case where both of them adopt their optimal strategy.

4 2 2 1 2
2 3 6
4 1 6
3 1 8

14

9 7 4 1 6
3 8 7
6 8 6
6 7 4
2 5 3
3 2 2
3 9 12
2 1 2
8 4 11

12

Hint

「Sample Explanation #1」

example

In a possible scenario, Ycy blocks the teleportation routes from node 11 to node 22 and from node 44 to node 22.

Glz moves the piece from node 11 to node 44, and from node 44 he teleports to node 33, and then moving to node 22, spending a total of 1414 coins.

「Constraints」

Subtasks are used in this problem.

Subtask Id nn \leq mm \leq Special Properties Score
#1 10001000 10510^5 No 1010
#2 10510^5 00
#3 10510^5
#4 10910^9 A 1515
#5 B
#6 No 4040
  • Special Property A: k=109k = 10^9.
  • Special Property B: k=0k = 0.

For all tests, it is guaranteed that 2n1052 \leq n \leq 10^5, 0m,k1090 \leq m,k \leq 10^9, 1S,T,ui,vin1 \leq S,T,u_i,v_i \leq n, 1wi1091 \leq w_i \leq 10^9, STS \neq T, uiviu_i \neq v_i. Nodes are numbered from 11 to nn.