Single Source Shortest Path
View as PDFSolve the Single Source Shortest Path problem.
Input Specification
Line : 
 
 (vertices), 
 
 (bidirectional edges)
Lines  to 
: 
 
, a bidirectional edge from 
 to 
 with weight 
. Multiple edges between the same pair of vertices may occur in the input.
Output Specification
Lines  to 
: line 
 has the length of the shortest path from vertex 
 to vertex 
. If no path exists, output 
-1.
Sample Input
4 3
1 2 2
1 3 5
2 3 2
Sample Output
0
2
4
-1
Comments