cho.sh
Notes
Loading...

Finding the K-th Shortest Path

Time limit

2s

Memory limit

256 MB

Problem

A traveler plans to move through several cities. Instead of always choosing only the shortest route, he wants a slightly different route that is still not too slow: the kkk-th shortest path.

Starting from city 111, write a program that finds the travel time of the kkk-th shortest path to every city.

Input

The first line contains the number of cities nnn, the number of roads mmm, and the rank kkk to find. The constraints are 1≤n≤10001 \le n \le 10001≤n≤1000, 0≤m≤2500000 \le m \le 2500000≤m≤250000, 1≤k≤1001 \le k \le 1001≤k≤100, and mk≤3000000mk \le 3000000mk≤3000000.

Each of the next mmm lines contains one road. A road is given by three integers aaa, bbb, and ccc, meaning that traveling from city aaa to city bbb takes time ccc. The constraints are 1≤a,b≤n1 \le a, b \le n1≤a,b≤n and 1≤c≤10001 \le c \le 10001≤c≤1000.

Cities are numbered from 111 to nnn. City 111 is the starting city. No two roads have both the same starting city and the same ending city.

Output

Print nnn lines. On the iii-th line, print the travel time of the kkk-th shortest path from city 111 to city iii.

The travel time of a path is the sum of the times of all roads on that path. The shortest path from city iii to the same city iii has length 000, but a general kkk-th shortest path may not have length 000. If the kkk-th shortest path does not exist, print −1-1−1.

A path may visit the same vertex more than once.

Hint

No additional hint is provided.