📜  门|门CS 2008 |第 45 题

📅  最后修改于: 2021-09-25 06:24:45             🧑  作者: Mango

当从下图中的顶点 a 运行时,Dijkstra 的单源最短路径算法计算正确的最短路径距离到

(A)只有顶点 a
(B)只有顶点 a, e, f, g, h
(C)只有顶点 a, b, c, d
(D)所有顶点答案: (D)
说明: Dijkstra 的单源最短路径不保证适用于具有负权重边的图,但它适用于给定的图。
让我们来看看…

Let us run the 1st pass
b 1
b is minimum, so shortest distance to b is 1.

After 1st  pass, distances are
c 3, e -2.  
e is minimum, so shortest distance to e is -2

After 2nd pass, distances are
c 3, f 0.  
f is minimum, so shortest distance to f is 0

After 3rd pass, distances are
c 3, g 3.  
Both are same, let us take g. so shortest distance to g is 3.

After 4th pass, distances are
c 3, h 5  
c is minimum, so shortest distance to c is 3

After 5th pass, distances are
h  -2
h is minimum, so shortest distance to h is -2

这个问题的测验