Homework 09: Dijkstra Shortest Path Solution






Submit your answer to this question via PC^2 under your account by the posted due time. No late submissions will be accepted. Note that homework is opened-book, but no outside assistance is permitted.




Dijkstra’s algorithm is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.


Write a program that returns the shortest distance from node X to node Y on a given directed acyclic graph (DAG), e.g.,





Note that the last two bits of input represent the starter node X and destination node Y. Also, the size of the given DAG could be varying in this problem.


Sample input







Sample output



The shortest distance from A to E is 5


The shortest distance from A to C is 3


error: Content is protected !!