In a country there are
Ema loves to travel, but doesn't like transferring between buses. On her trip
she wants to use at most
Help her answer
Input Specification
The first line contains two positive integers
The
The next line contains two positive integers
The
Output Specification
Print -1
if there is no trip
that satisfies the requirements.
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 15 | |
2 | 15 | |
3 | 25 | |
4 | 15 | No additional constraints. |
Sample Input 1
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
1 3
1 4
4 2
3 3
Sample Output 1
10
-1
0
Explanation for Sample Output 1
The answer to the first query from each example is marked on the graph.
Sample Input 2
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
2 3
1 4
4 2
3 3
Sample Output 2
6
4
0
Sample Input 3
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
3 3
1 4
4 2
3 3
Sample Output 3
3
4
0
Comments