Task
You are given an undirected weighted graph with nodes and edges. You are also given two integers: and .
Your task is to determine the minimum cost path from node to node , with the following conditions:
- The path is not required to be simple, meaning you may traverse the same edge multiple times.
- At each step along the path, you have two options:
- You can traverse a single edge, paying its original cost.
- You can choose to traverse consecutive edges (for some ), where the cost of each edge is replaced with instead of its original cost.
Important constraint:
The values of you choose must be pairwise distinct, meaning that each shortcut can be used at most once in the entire path.
For example, if you use a shortcut of length , you cannot use length again — but you may still use or , as long as each is unique.
Input data
On the first line, there will be the four numbers , , , and with the meaning from the statement, separated by a single space.
On the next lines, the edges of the graph will be described.
On each such line, there will be numbers: , , (separated by a single space), meaning that there is an edge between nodes and with cost .
Output data
The first line will contain a single number, representing the minimum cost of a path from node to node .
Constraints and clarifications
- The given graph is connected.
Example 1
stdin
8 12 4 3
1 2 2
1 3 2
1 4 3
2 3 3
2 4 5
3 4 5
3 5 4
5 6 3
5 7 5
7 8 2
6 7 3
6 8 5
stdout
10
Example 2
stdin
4 5 2 1
1 2 4
2 3 1
2 4 2
1 3 3
3 4 3
stdout
2