In Dhaka, there are too many vehicles. So, the result is well known, yes, traffic jam. So, mostly people have to spend quite a time in the roads to go from one place to another.
Now, the students have finally found a solution to this problem. The idea is to make all the roads one way. That means a vehicle can go through the roads in one way only. And to make the number of vehicles low, each vehicle has to pay a toll to use a road. Now you want to go from a place s to another place t. And you have a total of p taka in your pocket. Now you want to find the path which contains the highest toll road, to go from s to t. Remember that you can't use more than p taka.
For the given picture, s = 1, t = 5 and p = 10. There are three paths from 1 to 5.
- Path 1: 1 - 2 - 5, total toll = 11 (> p).
- Path 2: 1 - 3 - 5, total toll = 9 (≤ p), 6 is the maximum toll.
- Path 3: 1 - 4 - 5, total toll = 9 (≤ p), 5 is the maximum toll.
The maximum toll for a road of all of the paths having total toll not greater than p is 6.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with five integers N (2 ≤ N ≤ 10000), M (1 ≤ M ≤ 50000), s (1 ≤ s ≤ N), t (1 ≤ t ≤ N) and p (1 ≤ p ≤ 106) where N means the number of junctions and M means the number of roads connecting the junctions. Then there will be M lines each containing three integers u v c. u and v are junctions and there is a road from u to v (1 ≤ u, v ≤ N, u ≠ v) and c (0 ≤ c ≤ 105) is the toll needed for that road. There can be multiple roads between two junctions.
Output
For each case, print the case number and the desired result. If no such result is found, print -1
.
Sample
Sample Input | Sample Output |
---|---|
2 5 6 1 5 10 1 2 7 2 5 4 1 3 6 3 5 3 1 4 5 4 5 4 2 1 1 2 10 1 2 20 | Case 1: 6 Case 2: -1 |
Notes
Dataset is huge, use faster I/O methods.