[英]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). 确定给定边缘是锁定边缘还是未锁定边缘需要O(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? 对于给定的两个顶点s , t和一个正数k = O(1),我如何找到s和t之间最多包含k个锁定边的最短路径?
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? 对于给定的两个顶点s , t和一个正数k = O(1),我如何找到s和t之间的最短路径,该路径包含恰好有 k个锁定边?
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. 我不知道我怎么能在这个图运行Dijkstra算法找出给定顶点之间的最短路径,以及如何改造无向图,为导演之一。
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}. 您可以通过制作k
个图的副本(例如G_0,...,G_k)并修改每个图,以使G_i中的锁定边vw变为从G_i中的u到G_ {i中的v的边,来解决这两个问题。 +1},然后从G_i中的v到G_ {i + 1}中的u。 Then you can do single-source shortest paths from your root in G_0. 然后,您可以从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. 第二个查询通过读取G_k中距目标的距离来解决,而第一个查询则通过读取G_k中距目标的最小距离来解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.