Finding the shortest path

Report a typo

Below is a weighted undirected graph:

This is a weighted undirected graph

Find all the shortest paths from the node EE to all other nodes of the graph using Dijkstra's algorithm. As an answer, print edges of the shortest path tree. Edges' order does not matter. The last line of your answer should contain the shortest distance from EE to every node of a graph (nodes are sorted in alphabetical order, the shortest distance from EE to EE is 0).

Below is an example that clarifies the expected output format:

A B
B C
C D
0 2 3 5

Here, the first three lines correspond to three edges of the shortest path tree (an edge from AA to BB, an edge from BB to CC, and an edge from CC to DD), while the last line corresponds to the shortest distance from the starting node to every node of a graph. The starting node is AA, the shortest distance from AA to AA is 0, from AA to BB – 2, from AA to CC – 3, from AA to DD – 5.

Enter a short text
___

Create a free account to access the full topic