Loading...
Loading...
Loading...
A depot is in town 1. There are n towns and m two-way roads "a b w" with cost w. For every town from 1 to n print the lowest cost of a trip from the depot, or -1 if the town cannot be reached.
Example
Input
5 3 1 2 3 2 3 4 1 3 10
Output
0 3 7 -1 -1
Towns 4 and 5 have no road.
Try the problem first. Open one hint at a time.
Run Dijkstra once from town 1 and read all distances.
Replace infinity by -1 only when printing.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor