so I faced this question and I hope that someone can help me in it.
Given an undirected graph G = (V, E), 2 vertices x,y and an edge e = (v,u).
Suggest an algorithm to find if there's a simple path from x to y that includes the edge e.
So the focus here is on the simple path and not a regular path, for a regular path it's an easy problem using the BFS to search a path from x to v and a path from u to y.
I know that the problem can be solved using the max-flow approach but I just don't recognize how to build a new graph that can implement a max-flow algorithm on it so it tells whether the above criterion is achieved or not, I hope for help.
Thanks in advance.
Without sharing edges (edge-independent)
You could solve max flow with +1 sources at x and y, and -1 sinks at u and v.
Remove the edge e, and set all other edges to capacity 1.
A simple path from x to y via edge e exists if and only if you can find a flow of 2 in this new max flow problem.
Without sharing vertices (vertex-independent i.e. simple path)
Split each vertex
v[i]
in the original graph into two vertices,a[i]
andb[i]
.For each undirected edge between
v[i]
andv[j]
in the original, add directed edgesb[j]
toa[i]
andb[i]
toa[j]
with capacity 1.Also add a directed edge from
a[i]
tob[i]
with capacity 1 for each vertexv[i]
.The idea is that flow must always arrive at an
a[i]
vertex, and leave from ab[i]
vertex, after passing through the capacity 1 bottleneck froma[i]
tob[i]
. This ensures that each vertex can only be used once.With this new graph, proceed as for the edge-independent case.