4
votes

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

2
Are you asking how to find the shortest path? Or how to efficiently recalculate the shortest path after removing an edge? Either way, this question is a duplicate.BlueRaja - Danny Pflughoeft
no, i know dijkstra algorithm , but , as i said, we're allowed to turn one edge weight to zero(NOT REMOVE EDGE!), i wanna know how can solve this efficiently , using dijkstra or another way!user1711001
Djikstra's should handle edge-weights of 0 with no issues.BlueRaja - Danny Pflughoeft
i know , but original graph doesn't have 0-weight edge, i must determine turning which edge to zero results minimum path from start to end,user1711001

2 Answers

8
votes

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.

-1
votes

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.