shortest path with one edge turn to zero

大憨熊 提交于 2019-12-05 02:24:40

问题


given an undirected weighted graph G , and two vertices: start vertex and end vertex

what's the most efficient algorithm that finds the shortest path from start to end with ability to turn weight of exactly one edge to zero?

EDIT: i know dijkstra algorithm , but as i said , situation is different in this problem: we're allowed to turn one edge to zero,

i wanna know how solve this problem efficiently, actually , one way is turn edges weights to zero iteratively! and apply dijkstra algorithmin each step, but , i'm looking for more efficient way

thanks


回答1:


You can solve this by using Djikstra's algorithm on an augmented graph of twice the size.

Suppose you have vertices 1...n.

Define a new graph such that for each edge a->b with weight w in the original, define edges a->b with weight w, a->b+n with weight 0, and a+n->b+n with weight w.

The idea is that the vertices n+1..n+n are duplicates containing a copy of the original graph. Moving from the original to the duplicate represents using your special ability of turning an edge to 0. Note that once you are in the duplicate there is no way of returning to the original graph so this special ability can only be used once.

Therefore you just need to solve the problem on the augmented graph of going from start to end+n to find the shortest path including your ability to set a single weight to 0.




回答2:


Dijkstra's algorithm is commonly used to solve these types of problems. Also, this sounds a bit like the TSP problem, I could be wrong on that part though.



来源:https://stackoverflow.com/questions/14104718/shortest-path-with-one-edge-turn-to-zero

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!