You are given a directed acyclic graph of 'N' vertices(0 to 'N' - 1) and 'M' weighted edges.
Return an array that stores the distance(sum of weights) of the shortest path from vertex 0 to all vertices, and if it is impossible to reach any vertex, then assign -1 as distance.
'N' = 3, 'M' = 3, 'edges' = [0, 1, 2], [1, 2, 3], [0, 2, 6]].

Distance (0 to 0) = 0.
Distance (0 to 1) = 2.
Distance (0 to 2) = 0->1 + 1->2 = 2+3 = 5.
So our answer is [0, 2, 5].
The first line contains two integers, 'N', and 'M'.
The next 'M' lines contain three integers each, 'u', 'v', and 'w', representing there is a directed edge from 'u' to 'v' of weight 'w'.
Output format:
The only line contains an array that stores the distance(sum of weights) of the shortest path from vertex 0 to all vertices, and if it is impossible to reach any vertex, then assign -1 as distance.
Note:
You don’t need to print anything, it has already been taken care of. Just complete the given function.
3 3
2 0 4
0 1 3
2 1 2
0 3 -1

Distance (0 to 0) = 0.
Distance (0 to 1) = 3.
Distance (0 to 2) = We cannot reach vertex 2 from 0.
So our answer is [0, 3, -1].
4 4
2 1 5
0 2 3
0 1 2
2 3 1
0 2 3 4
1 <= 'N', 'M' <= 10^5
1 <= edge weight <= 10^5
Time Limit: 1 sec
Think of using Dijkstra Algorithm to find the shortest distances.
Approach:
Algorithm:
O(N+M*log(N)), where 'N' and 'M' are the number of vertices and the number of edges, respectively.
We are traversing through all edges and inserting elements in the priority queue, so the overall time complexity is O(N+M*log(N)).
O(N+M), where 'N' and 'M' are the number of vertices and the number of edges, respectively.
We are creating 'pq' and 'dis'. Hence the space complexity is O(N+M).