Here is the Algorithm:
Topologically sort the Vertices of G
Initialize - Single - Source(G,s)
for each vertex u, taken in topologically sorted order
for each vertex v in G.Adjacent[u]
Relax(u,v,w)
For each vertex u , you only iterate through the edges that go out from u . Each distinct edge is visited only once, and that's why the algorithm takes O(V+E) time.
This assumes you are using a graph representation (like adjacency lists, not a matrix) that allows quick access to every vertex's adjacent edges. The topological sort also requires this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.