The country of Beanland consists of towns connected by two-way roads. Mr. Bean, the leader of Beanland, has ordered each town to produce beans. Each town is ordered to produce a different type of bean, and these beans are then transported between towns. However, because the towns are far apart, it is possible the beans could spoil before reaching the next town.
Each road in Beanland has a length and a start and end town, and . All the towns in Beanland are guaranteed to be connected, meaning it is always possible to travel from one town to another along the two-way roads.
For each pair of two towns in Beanland, there is an optimal path. An optimal path is a path with the lowest sum of edge lengths. If the length of the optimal path is greater than , the beans will spoil in transport.
Mr. Bean, in order to save the beans, has a magical Bean Wand. If he waves the Bean Wand, he can reduce the length of all the roads by , to a minimum length of . However, he can only use this wand once. Mr. Bean would like to know what the smallest possible value of is so that all beans can travel along the optimal path between any pair of cities without spoiling.
For this question, Python users are recommended to use PyPy in order to pass the time limit.
Input Specification
The first line of input will contain three space-separated integers, , , and , the number of towns, the number of two-way roads, and the maximum allowed optimal path length.
The next lines of input will contain three space-separated integers each, , and .
Output Specification
Output the smallest non-negative integer that Mr. Bean can use without any beans spoiling in transport.
Subtasks
Subtask 1 [30%]
Sample Input 1
4 4 2
1 2 1
2 3 3
2 4 3
3 4 7
Sample Output 1
2
Sample Explanation 1
By setting to , the edge from to equals to , to is equal to , to is equal to , and to is equal to . It can be determined that all of the optimal paths will now be or less.
Sample Input 2
5 6 7
1 2 6
1 5 8
2 5 7
2 3 9
4 3 3
4 5 4
Sample Output 2
3
Comments