#FW0000120. Lối đi xuyên rừng (A Walk Through the Forest)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 intersections and roads, at most one road per pair. Jimmy walks from intersection (work) to intersection (home). He may move from to only when the shortest-path distance from to home is strictly smaller than that from to home. Count all distinct valid routes. The answer is guaranteed not to exceed .
Input
First line ; then undirected weighted edges . This one-case adaptation has no terminal 0 marker.
Output
Print the number of valid routes.
Subtasks
-
Subtask 1 (40 points): , , . All input conditions remain in force.
-
Subtask 2 (60 points): , , . 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.