Converting between shortest path problems

51 Views Asked by At

Given a weighted digraph $G$, and collections of vertices $R, S \subset V$ , consider the problem of finding a shortest length path joining a vertex $r\in R$ to a vertex $s\in S$. Reduce this to the shortest path problem from a given vertex to all other vertices.

I have been looking at this question for a while and I'm struggling to articulate what I am thinking. Clearly I should start by taking some fixed $a\in R$ and finding all the shortest paths from a to every other vertex, but I am unsure how to create the paths from any other $r\in R \setminus a$ to $s\in S$ since I cannot guarantee they are the shortest.

1

There are 1 best solutions below

0
On BEST ANSWER

Introduce a dummy "supersource" node $r_0$ and a directed arc with weight $0$ from $r_0$ to each $r\in R$. Now solve a shortest path problem from $r_0$ to all vertices. Let $d(r_0,i)$ be the resulting shortest-path distances. For the path that corresponds to $\min_{s\in S} d(r_0,s)$, the first arc indicates which $r\in R$ to use.

A similar idea with an additional dummy supersink node $s_0$ further reduces the problem to a single-source, single-sink shortest path problem.