正在加载图片...
The Shortest Path Problem Input:A weighted directed graph G=(E),where V1,2,...,; Output:The distance from vertex 1 to every other vertex in G; 1.={1;-{1;[1]←-0; ■ 2.for v2 to n ■ 3. if yis adjacent to1 then 2[☑k--length1,☑; ■ 4. else [y☑k-o; ■ 5. end if; 6.end for; 7.for六-1tor1 ■ 8. Let ye ybe such that a[y]is minimum; 9. Xxoy);//add vertex ytoX 10. Yy);//delete vertex yfrom Y 11. for each edge (y,w) 12. if we Yand i[y]+lengthly,w]<a[w]then 13. 2[M←-[☑+ength[y,WM: 14 end for; ■ 15. end for;The Shortest Path Problem ◼ Input: A weighted directed graph G=(V, E), where V={1, 2, …, n}; ◼ Output: The distance from vertex 1 to every other vertex in G; ◼ 1. X={1}; YV-{1}; [1]0; ◼ 2. for y2 to n ◼ 3. if y is adjacent to 1 then [y]length[1, y]; ◼ 4. else [y]; ◼ 5. end if; ◼ 6. end for; ◼ 7. for j1 to n-1 ◼ 8. Let yY be such that [y] is minimum; ◼ 9. XX{y}; //add vertex y to X ◼ 10. YY-{y}; //delete vertex y from Y ◼ 11. for each edge (y, w) ◼ 12. if wY and [y]+length[y, w]<[w] then ◼ 13. [w][y]+length[y, w]; ◼ 14. end for; ◼ 15. end for;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有