Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started