#P8426. Detour Route in Beaverland

    ID: 21602 Type: Default 1000ms 256MiB

Detour Route in Beaverland

Detour Route in Beaverland

In Beaverland, there are NN cities numbered from 11 to NN, and MM bidirectional roads. The ii-th road connects cities AiA_i and BiB_i and has length CiC_i. It is guaranteed that any city is reachable from any other city by some sequence of roads.

Bitaro, a beaver living in city 11, goes to school in city NN every day using one of the shortest paths (with distance LL, the minimum distance from city 11 to city NN). 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 NN) to his home (city 11) 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 NN to city 11 that meets the conditions.

inputFormat

The input begins with two integers NN and MM (2N1052 \le N \le 10^5, 1M2×1051 \le M \le 2\times10^5) on the first line, representing the number of cities and the number of roads respectively. The next MM lines each contain three integers AiA_i, BiB_i, and CiC_i (1Ai,BiN1 \le A_i,B_i \le N, 1Ci1091 \le C_i \le 10^9), describing a road between cities AiA_i and BiB_i with length CiC_i. 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 NN to city 11 with a length strictly greater than the shortest distance (L) from city 11 to city NN (and without repeating any city). Otherwise, output “NO”.

sample

4 4
1 2 1
2 4 1
1 3 1
3 4 1
NO