Problem Statement

Given a weighted graph with non-negative weights and a source vertex, return the shortest distance from the source to all vertices.

Examples

1Example 1
Input:
{ "V": 3, "adj": [ [ [ 1, 1 ], [ 2, 6 ] ], [ [ 0, 1 ], [ 2, 3 ] ], [ [ 0, 6 ], [ 1, 3 ] ] ], "S": 2 }
Output:
[ 4, 3, 0 ]
2Example 2
Input:
{ "V": 5, "adj": [ [ [ 1, 2 ], [ 2, 4 ] ], [ [ 0, 2 ], [ 2, 1 ], [ 3, 7 ] ], [ [ 0, 4 ], [ 1, 1 ], [ 4, 3 ] ], [ [ 1, 7 ], [ 4, 1 ] ], [ [ 2, 3 ], [ 3, 1 ] ] ], "S": 0 }
Output:
[ 0, 2, 3, 7, 6 ]
3Example 3
Input:
{ "V": 4, "adj": [ [ [ 1, 5 ] ], [ [ 0, 5 ], [ 2, 2 ] ], [ [ 1, 2 ] ], [] ], "S": 0 }
Output:
[ 0, 5, 7, 1000000000 ]
Loading...

Sign in to Run Code and Submit