Question: Coding Problem Problem Name: Algorithm Problem Level: HARD Problem Description: ####Given an undirected, connected and weighted graph G(V, E) with V number of vertices (which

Coding Problem Problem Name: Algorithm Problem Level: HARD Problem Description: ####Given an undirected, connected and weighted graph G(V, E) with V number of vertices (which are numbered from 0 to V-1) and E number of edges. ####Find and print the shortest distance from the source vertex (i.e. Vertex 0) to all other vertices (including source vertex also) using Dijkstra's Algorithm. ####Print the ith vertex number and the distance from source in one line separated by space. Print different vertices in different lines. #####Note : Order of vertices in output doesn't matter. #####Input Format :  Line 1: Two Integers V and E (separated by space) Next E lines : Three integers ei, ej and wi, denoting that there exists an edge between vertex ei and vertex ej with weight wi (separated by space) #####Output Format :  In different lines, ith vertex number and its distance from source (separated by space) #####Constraints :  ####2 <= V, E <= 10^5 #####Sample Input 1 : 4 4 0 1 3 0 3 5 1 2 1 2 3 8 #####Sample Output 1 : 0 0 1 3 2 4 3 5 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!