#P2901. [USACO08MAR] Cow Jogging G

    ID: 1944 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2008USACO广度优先搜索,BFSK 短路A*算法

[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 MM roads in total, each connecting two pastures. The pastures are numbered from 11 to NN. If X>YX > Y, it means pasture XX is higher than pasture YY, i.e., downhill roads go from XX to YY. Pasture NN is the barn (the highest point), and pasture 11 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 KK different routes. To avoid getting too tired, she wants these KK routes to be the KK 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 KK shortest paths in the pasture network. You are given a list of roads between pastures, where each road is represented by (Xi,Yi,Di)(X_i, Y_i, D_i), meaning there is a downhill road from XiX_i to YiY_i of length DiD_i.

Input Format

The first line contains three space-separated integers N,M,KN, M, K.

Each of the next MM lines contains three space-separated integers Xi,Yi,DiX_i, Y_i, D_i, describing a downhill road.

Output Format

Output KK lines. On the ii-th line, output the length of the ii-th shortest route. If fewer than KK routes exist, output 1-1 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 (51)(5 \to 1), (531)(5 \to 3 \to 1), (521)(5 \to 2 \to 1), (5321)(5 \to 3 \to 2 \to 1), (5431)(5 \to 4 \to 3 \to 1), and (54321)(5 \to 4 \to 3 \to 2 \to 1).

Constraints: For all test points, it is guaranteed that 1N1,0001 \le N \le 1,000, 1M1×1041 \le M \le 1 \times 10^4, 1K1001 \le K \le 100, 1Yi<XiN1 \le Y_i < X_i \le N, 1Di1×1061 \le D_i \le 1 \times 10^6.

Translated by ChatGPT 5