PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000120. Lối đi xuyên rừng (A Walk Through the Forest)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lối đi xuyên rừng (A Walk Through the Forest)

A Walk Through the Forest

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected positive-weighted graph has nn intersections and mm roads, at most one road per pair. Jimmy walks from intersection 11 (work) to intersection 22 (home). He may move from uu to vv only when the shortest-path distance from vv to home is strictly smaller than that from uu to home. Count all distinct valid routes. The answer is guaranteed not to exceed 231−12^{31}-1.

Input

First line n,mn,m; then mm undirected weighted edges u,v,wu,v,w. This one-case adaptation has no terminal 0 marker.

Output

Print the number of valid routes.

Subtasks

  • Subtask 1 (40 points): 2≤n≤82\le n\le 8, 0≤m≤160\le m\le 16, 1≤w≤401\le w\le 40. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤10002\le n\le 1000, 0≤m≤n(n−1)/20\le m\le n(n-1)/2, 1≤w≤1061\le w\le 10^6. All input conditions remain in force.

Examples

Input

5 6
1 3 2
1 4 2
3 4 3
1 5 12
4 2 34
5 2 24

Output

2

Explanation

The two valid walks are 1->4->2 and 1->5->2; moving through 3 to 4 does not strictly reduce the remaining distance.