


1. There are no self-loops(an edge connecting the vertex to itself) in the given graph.
2. There are no parallel edges i.e no two vertices are directly connected by more than 1 edge.
Input:
4 5
0 1 5
0 2 8
1 2 9
1 3 2
2 3 6

The source node is node 0.
The shortest distance from node 0 to node 0 is 0.
The shortest distance from node 0 to node 1 is 5. In the above figure, the green path represents this distance. The path goes from node 0->1, giving distance = 5.
The shortest distance from node 0 to node 2 is 8. In the above figure, the pink path represents this distance. The path goes from node 0->2, giving distance = 8.
The shortest distance from node 0 to node 3 is 7. In the above figure, the yellow path represents this distance. The path goes from node 0->1->3, giving distance = 7.
The first line contains three space-separated integers ‘V’, ‘E’ and 'S', denoting the number of vertices, the number of edges in the undirected graph and starting vertex, respectively.
The next ‘E’ lines each contain three single space-separated integers ‘u’, ‘v’, and ‘distance’, denoting a node ‘u’, a node ‘v’, and the distance between nodes (u, v), respectively.
The only line contains the list of integers denoting the shortest distance between each node and source vertex 'S'.
The idea is to maintain two arrays, one stores the visited nodes, and the other array stores the distance (element at index ‘i’ denotes the distance from node 0 to node ‘i’). We pick an unvisited minimum distance vertex, then update the distance of all its adjacent vertices considering the path from source to an adjacent vertex to pass through the picked minimum distance vertex. Repeat the process till all nodes are visited.
The idea is to use a priority queue which creates a min-heap for us. In the priority queue, we will be storing the ‘distance’ and node ‘v’ which will give us the minimum distance vertex. We will pick an unvisited minimum distance vertex which will be the first element of the priority queue, then update the distance of all its adjacent vertices (using adjacency list) considering the path from source to an adjacent vertex to pass through the picked minimum distance vertex. Repeat the process till the priority queue is empty.