#P2901. [USACO08MAR] Cow Jogging G
[USACO08MAR] Cow Jogging G
Description
Bessie has finally tasted the consequences of laziness and decides to jog from the barn to the pond several times a week to get in shape. Of course, she does not want to overexert herself, so she only plans to jog downhill from the barn to the pond, then leisurely walk back to the barn.
At the same time, Bessie does not want to run too far, so she wants to run along the shortest route to the pond. There are roads in total, each connecting two pastures. The pastures are numbered from to . If , it means pasture is higher than pasture , i.e., downhill roads go from to . Pasture is the barn (the highest point), and pasture is the pond (the lowest point).
However, after a week, Bessie gets bored of the monotony and wants to try different routes. For example, she hopes there can be different routes. To avoid getting too tired, she wants these routes to be the shortest routes from the barn to the pond. Two routes are considered different if the sequences of roads they contain are different.
Please help Bessie compute her training intensity by finding the lengths of the shortest paths in the pasture network. You are given a list of roads between pastures, where each road is represented by , meaning there is a downhill road from to of length .
Input Format
The first line contains three space-separated integers .
Each of the next lines contains three space-separated integers , describing a downhill road.
Output Format
Output lines. On the -th line, output the length of the -th shortest route. If fewer than routes exist, output for the remaining lines. If multiple distinct routes have the same length, they should all be counted; equal lengths may appear multiple times.
5 8 7
5 4 1
5 3 1
5 2 1
5 1 1
4 3 4
3 1 1
3 2 1
2 1 1
1
2
2
3
6
7
-1
Hint
Sample 1 Explanation: These routes are , , , , , and .
Constraints: For all test points, it is guaranteed that , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号