Courier Kari must deliver a package through weighted streets. Find the minimum travel cost from the depot to every district; unreachable districts are marked -1.
Input: n m s, then m undirected edges u v w. Output: n distances from s in vertex order.
Example 1:
Input: 4 4 1
1 2 3
2 3 4
1 3 10
3 4 2
Output: 0 3 7 9
Example 2:
Input: 3 1 2
1 2 5
Output: 5 0 -1
Example 3:
Input: 1 0 1
Output: 0
Constraints:
1≤n≤100000; 0≤m≤200000; 0≤w≤10^9.
Tags:
graphs dijkstra shortest-path
Loading...
Test Cases:No test cases
No test cases available.
Kari’s Budget Courier - MEDIUM Coding Problem | CodeTikki