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 缺点是不能用在回环图里。
本文探讨了如何在有向图中找到从任意顶点到指定源顶点的加权最短路径,并计算不同最小路径的数量。讨论了使用Dijkstra算法的局限性,提出了一种结合拓扑排序的改进方案。
2707

被折叠的 条评论
为什么被折叠?



