Beaverland consists of cities, numbered from to . There are roads connecting cities, numbered from to . The road connects the city and the city bidirectionally, and the length of the road is . It is possible to move from any city to any other city by passing through a number of roads.
Bitaro is a beaver living in the city . He goes to a school in the city . He usually takes the same route to the school. His route to the school satisfies the following conditions.
- Let be the minimum distance from the city to the city .
- Bitaro's route to the school connects the city and the city , and its length is .
Since today is a fine day, Bitaro decided to go back to his home by taking a roundabout way. Namely, he will take a route longer than from the city to the city . Since Bitaro is easily bored, he does not want to visit the same city more than once. Therefore, when he takes a roundabout way to his home, it is not allowed to visit the same city more than once, and it is not allowed to turn back on the way.
Given information of the cities and the roads in Beaverland, write a program which determines whether there exists a roundabout way from the school to Bitaro's home.
Input Specification
Read the following data from the standard input. Given values are all integers.
Output Specification
Write one line to the standard output. Output if there exists a route to Bitaro's home longer than without visiting the same city more than once. Otherwise, output .
Constraints
- .
- .
- .
- .
- It is possible to move from any city to any other city by passing through a number of roads.
Subtasks
- (7 points) .
- (15 points) .
- (23 points) .
- (35 points) For any distinct cities , there is a route from the city to the city without passing through the city .
- (20 points) No additional constraints.
Sample Input 1
4 4
1 2 1
1 3 2
2 4 4
3 4 3
Sample Output 1
0
Explanation for Sample 1
In this sample input, the minimum distance from the city (Bitaro's home) to the city (school) is .
There are two routes to Bitaro's home without visiting the same city more than once.
- A route of length passing through the roads in this order, and visiting the cities in this order.
- A route of length passing through the roads in this order, and visiting the cities in this order.
Since there does not exist a route to Bitaro's home longer than without visiting the same city more than once, output .
This sample input satisfies the constraints of all the subtasks.
Sample Input 2
4 4
1 2 1
1 3 3
2 4 4
3 4 3
Sample Output 2
1
Explanation for Sample 2
In this sample input, the minimum distance from the city (Bitaro's home) to the city (school) is .
There are two routes to Bitaro's home without visiting the same city more than once.
- A route of length passing through the roads in this order, and visiting the cities in this order.
- A route of length passing through the roads in this order, and visiting the cities in this order.
Since there exists a route to Bitaro's home longer than without visiting the same city more than once, output .
This sample input satisfies the constraints of all the subtasks.
Sample Input 3
3 4
1 2 1
1 2 2
1 3 3
1 3 3
Sample Output 3
0
This sample input satisfies the constraints of Subtasks 1, 2, 3, 5.
Sample Input 4
4 5
1 2 1
1 3 2
2 4 4
3 4 3
2 3 1
Sample Output 4
1
This sample input satisfies the constraints of all the subtasks.
Sample Input 5
12 17
2 4 656247308
4 6 106088453
1 5 754343261
9 12 497827261
3 8 759830309
3 4 61084725
1 6 324702188
3 6 415317430
7 12 846175092
5 8 278621369
1 10 891247646
10 12 755236904
6 8 511967203
5 6 597197970
1 7 800309458
7 9 348347831
10 11 134217757
Sample Output 5
0
This sample input satisfies the constraints of Subtasks 1, 2, 3, 5.
Comments