Shortest Cable Lengths
Junctions are joined by cables (undirected) with positive lengths. Print the shortest distance from junction to every junction ( if unreachable). Use Dijkstra's algorithm with a priority queue.
Input
and , lines u v length, then .
Output
distances on one line.
Constraints
, , length — use 64-bit distances.
Sample 1
Input
4 4 1 2 4 1 3 1 3 2 2 2 4 5 1
Output
0 3 1 8