简体   繁体   中英

Minimum path in an undirected graph with locked and unlocked edges

Given an undirected graph with positive weights , there are 2 kinds of edges: locked edges and unlocked edges. Determination if a given edge is either locked or unlocked edge takes O(1).

  1. For given two vertices s , t and a positive number k = O(1), how can I find the shortest path between s and t which contains at most k locked edges?

  2. For given two vertices s , t and a positive number k = O(1), how can I find the shortest path between s and t which contains exactly k locked edges?

I'm not sure how can I run Dijkstra algorithm on this graph to find the shortest path between the given vertices, and how can I transform the undirected graph, into an directed one.

You can solve both of your problems by taking k copies of the graph, say G_0, ..., G_k, and modifying each graph so that a locked edge vw in G_i turns into an edge from u in G_i to v in G_{i+1} and from v in G_i to u in G_{i+1}. Then you can do single-source shortest paths from your root in G_0. The second query is solved by reading off the distance to the target in G_k, while the first is solved by reading off the minimum distance in any G_i to the target.

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