SPFA
Which is SPFA?
S P F A = S h o r t e s t P a t h F a s t e r A l g o r i t h m SPFA=Shortest\ Path\ Faster\ Algorithm SPFA=Shortest Path Faster Algorithm
思想:bfs ( b r e a t h f i r s t s e a r c h breath\ first\ search breath first search )
SPFA = Bellman-Ford plus
SPFA多用于解决 单源最短路
时间复杂度:O(VE)
What will we need?
队列(queue)q、标记数组dist[N]
How to use it?
设dist数组为无穷大(INT_MAX o r or or inf)
源点入队
队首元素(a)出队,以a为起点的所有连边的终点做松弛操作
将所有与源点有关联的所有点入队列
依次取出队首元素,将与队首元素有连边的所有顶点进行松弛
如果松弛不成功,则元素出队,终点元素不入队,继续进行下一次操作
终止条件:队列为空 while(!que.empty())