Under construction

Still being built. Things may change

School Road

Time limit2sMemory limit1024 MB

Summary
Given a weighted connected graph and shortest distance L from city 1 to city N, decide whether a simple path from N back to 1 longer than L exists.
Level

Medium7 of 10

Topics
Shortest path, Graph, DFS
Solved
No attempts yet

Problem

Beaverland consists of NN cities, numbered from 11 to NN. There are MM roads connecting cities, numbered from 11 to MM. Road ii (1≤i≤M1 \le i \le M) connects city AiA_i and city BiB_i in both directions, and its length is CiC_i. You can travel from any city to any other city by passing through some number of roads.

Bitaro is a beaver who lives in city 11. He goes to school in city NN. He usually takes the same route to school. That route satisfies the following conditions.

  • Let LL be the minimum distance from city 11 to city NN.
  • Bitaro's route to school connects city 11 and city NN, and its length is LL.

Today is a fine day, so Bitaro decides to take a roundabout way home. He will take a route from city NN to city 11 that is longer than LL. Bitaro gets bored easily, so he does not want to visit the same city more than once. On the way home, he may not visit the same city twice, and he may not turn back.

Given the cities and roads of Beaverland, write a program that determines whether a roundabout way from school to Bitaro's home exists.

Input

The first line contains NN and MM.

A1A_1 B1B_1 C1C_1

A2A_2 B2B_2 C2C_2

⋮\vdots

AMA_M BMB_M CMC_M

Output

Write one line. Print 11 if there is a route from city NN to city 11 that is longer than LL and visits no city more than once. Otherwise, print 00.

Constraints

  • 2≤N≤100 0002 \le N \le 100\,000.
  • 1≤M≤200 0001 \le M \le 200\,000.
  • 1≤Ai<Bi≤N1 \le A_i < B_i \le N (1≤i≤M1 \le i \le M).
  • 1≤Ci≤1 000 000 0001 \le C_i \le 1\,000\,000\,000 (=109= 10^9) (1≤i≤M1 \le i \le M).
  • You can travel from any city to any other city by passing through some number of roads.

Examples5

  1. Example 1

    Input
    4 4
    1 2 1
    1 3 2
    2 4 4
    3 4 3
    
    Expected output
    0
    
  2. Example 2

    Input
    4 4
    1 2 1
    1 3 3
    2 4 4
    3 4 3
    
    Expected output
    1
    
  3. Example 3

    Input
    3 4
    1 2 1
    1 2 2
    1 3 3
    1 3 3
    
    Expected output
    0
    
  4. Example 4

    Input
    4 5
    1 2 1
    1 3 2
    2 4 4
    3 4 3
    2 3 1
    
    Expected output
    1
    
  5. Example 5

    Input
    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
    
    Expected output
    0