Home > Net >  How to find 2 vertex-disjoint paths in a graph with both paths having same source but different dest
How to find 2 vertex-disjoint paths in a graph with both paths having same source but different dest

Time:06-01

Let's consider this graph:

enter image description here

Let's say I want first path with source as A, destination as H and I want second path with source as A, destination as D.

I am not able to apply suurballe algorithm as it works for paths with same source and same destination only. Expected O/p is first path => A-E-F-G-H, second path => A-B-C-D. These two are vertex disjoint paths. How to calculate 2 vertex disjoint paths in this situation?

CodePudding user response:

An approach that works quite well for many problems is to think about how to transform it into one you can solve.

In this case: You already know the Suurballe algorithm that can solve the problem of vertex disjoint paths if the target vertex of both is the same. So to solve your problem, you can just add a vertex X to your graph and connect D and H to it. Then execute Suurballe's algorithm with start A and target X and remove X from the end of the returned paths. As the only way to reach X is via D and H, those must be the last ones in the path before X.

  • Related