#P10838. 『FLA - I』庭中有奇树
『FLA - I』庭中有奇树
Description
In the game, Glz is given an unrooted tree with nodes, with a starting node and a destination node . 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 and with an edge of weight , then Glz can choose to move the piece from to , paying coins. At the beginning of the game the piece is at node . Glz needs to make the piece at node 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 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 possible teleportation routes. If Ycy blocks the teleportation route from node to node , the number of coins that it takes for Glz to teleport a piece from node to node becomes exactly 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 to node does not affect Glz's teleportation from node to node .
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 , , , and — 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 lines follow, each line contains three integers , , , representing an edge on the tree connecting nodes and , with a weight of .
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」

In a possible scenario, Ycy blocks the teleportation routes from node to node and from node to node .
Glz moves the piece from node to node , and from node he teleports to node , and then moving to node , spending a total of coins.
「Constraints」
Subtasks are used in this problem.
| Subtask Id | Special Properties | Score | ||
|---|---|---|---|---|
| #1 | No | |||
| #2 | ||||
| #3 | ||||
| #4 | A | |||
| #5 | B | |||
| #6 | No |
- Special Property A: .
- Special Property B: .
For all tests, it is guaranteed that , , , , , . Nodes are numbered from to .
京公网安备 11011102002149号