question from pta
Write a program to not only find the weighted shortest distances, but also count the number of different minimum paths from any vertex to a given source vertex in a digraph. It is guaranteed that all the weights are positive.
Dijkstra algorithm
- greedy
- weighted
遍历弊端
一开始简单敲入代码,思路是广度遍历,发现缺点是当一个节点距离改变时后几个节点已经计算好的距离需要重新计算。而且,似乎这并没有办法抢救。
抢救方案1:
先拓扑排序,再对拓扑排序的序列进行以上遍历。
Btw 缺点是不能用在回环图里。