简体   繁体   中英

Shortest path in an edge-weighted DAG with multiple source vertices?

Given an algorithm A that computes the longest path from a source vertex s in a DAG G with non-negative edge weights. What is the minimum number of times required to run the algorithm A to find the longest path in a DAG G?

One way is to figure out the multiple source vertices, this can be achieved in O(|Edges|). And then run Algorithm A with each of these vertices as a source vertex. This will require running algorithm A NumberOfSourceVertices times.

Can we do better ?

Yes, we can do better. Add a new node z to G . For every identified source vertex s , add an edge (z, s, 0) (zero edge weight) to G.

Run A once on the modified G .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM