#P8426. Detour Route in Beaverland
Detour Route in Beaverland
Detour Route in Beaverland
In Beaverland, there are cities numbered from to , and bidirectional roads. The -th road connects cities and and has length . It is guaranteed that any city is reachable from any other city by some sequence of roads.
Bitaro, a beaver living in city , goes to school in city every day using one of the shortest paths (with distance , the minimum distance from city to city ). Today, enjoying the fine weather, he decides to take a detour on his way back home. That is, he wants to choose a route from school (city ) to his home (city ) whose total length is (> L). While taking the detour, he does not wish to pass any city more than once and he is not allowed to traverse the same road back and forth (i.e. no immediate backtracking). Note that although he is not allowed to visit the same city twice on the detour route, passing through a city which appeared on his school route is allowed.
Your task is to determine whether there exists such a detour route from city to city that meets the conditions.
inputFormat
The input begins with two integers and (, ) on the first line, representing the number of cities and the number of roads respectively. The next lines each contain three integers , , and (, ), describing a road between cities and with length . It is guaranteed that the graph is connected.
outputFormat
Output a single line with the word “YES” if there exists a detour route from city to city with a length strictly greater than the shortest distance (L) from city to city (and without repeating any city). Otherwise, output “NO”.
sample
4 4
1 2 1
2 4 1
1 3 1
3 4 1
NO