시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB274480.000%

문제

Beaverland consists of $N$ cities, numbered from $1$ to $N$. There are $M$ roads connecting cities, numbered from $1$ to $M$. The road $i$ ($1 ≤ i ≤ M$) connects the city $A_i$ and the city $B_i$ bidirectionally, and the length of the road $i$ is $C_i$. 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 $1$. He goes to a school in the city $N$. He usually takes the same route to the school. His route to the school satisfies the following conditions.

  • Let $L$ be the minimum distance from the city $1$ to the city $N$.
  • Bitaro’s route to the school connects the city $1$ and the city $N$, and its length is $L$.

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 $L$ from the city $N$ to the city $1$. 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.

입력

Read the following data from the standard input. Given values are all integers.

$N$ $M$

$A_1$ $B_1$ $C_1$

$A_2$ $B_2$ $C_2$

$\vdots$

$A_M$ $B_M$ $C_M$

출력

Write one line to the standard output. Output $1$ if there exists a route to Bitaro’s home longer than $L$ without visiting the same city more than once. Otherwise, output $0$.

제한

  • $2 ≤ N ≤ 100\,000$.
  • $1 ≤ M ≤ 200\,000$.
  • $1 ≤ A_i < B_i ≤ N$ ($1 ≤ i ≤ M$).
  • $1 ≤ C_i ≤ 1\,000\,000\,000$ ($= 10^9$) ($1 ≤ i ≤ M$).
  • It is possible to move from any city to any other city by passing through a number of roads.

서브태스크

번호배점제한
17

$M ≤ 40$.

215

$N ≤ 18$.

323

$M - N ≤ 13$.

435

For any distinct cities $a$, $b$, $c$, there is a route from the city $a$ to the city $c$ without passing through the city $b$.

520

No additional constraints.

예제 입력 1

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

예제 출력 1

0

In this sample input, the minimum distance from the city $1$ (Bitaro’s home) to the city $4$ (school) is $5$. There are two routes to Bitaro’s home without visiting the same city more than once.

  • A route of length $5$ passing through the roads $3 → 1$ in this order, and visiting the cities $4 → 2 → 1$ in this order.
  • A route of length $5$ passing through the roads $4 → 2$ in this order, and visiting the cities $4 → 3 → 1$ in this order.

Since there does not exist a route to Bitaro’s home longer than $5$ without visiting the same city more than once, output $0$.

This sample input satisfies the constraints of all the subtasks.

예제 입력 2

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

예제 출력 2

1

In this sample input, the minimum distance from the city $1$ (Bitaro’s home) to the city $4$ (school) is $5$. There are two routes to Bitaro’s home without visiting the same city more than once.

  • A route of length $5$ passing through the roads $3 → 1$ in this order, and visiting the cities $4 → 2 → 1$ in this order.
  • A route of length $6$ passing through the roads $4 → 2$ in this order, and visiting the cities $4 → 3 → 1$ in this order.

Since there exists a route to Bitaro’s home longer than $5$ without visiting the same city more than once, output $1$.

This sample input satisfies the constraints of all the subtasks.

예제 입력 3

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

예제 출력 3

0

This sample input satisfies the constraints of Subtasks 1, 2, 3, 5.

예제 입력 4

4 5
1 2 1
1 3 2
2 4 4
3 4 3
2 3 1

예제 출력 4

1

This sample input satisfies the constraints of all the subtasks.

예제 입력 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

예제 출력 5

0

This sample input satisfies the constraints of Subtasks 1, 2, 3, 5.

채점 및 기타 정보

  • 예제는 채점하지 않는다.