Find a source-sink-path that touches a subset of edges

I have a directed graph that has a source node and a sink node and a subset of marked edges.

I need to find a path from source to sink that contains at least one marked edge and is cycle-free.

• What have you tried? What approaches have you already considered? What's the fastest algorithm you've come up with so far?
– D.W.
Dec 29 '15 at 18:30
• I have only implemented a solution that's not cycle-free. I ended up finding a better solution for my original problem that doesn't involve this question. @D.W. Dec 29 '15 at 22:26

If the path did not have to be cycle free this would be easy: let $s$ and $t$ be the source/sink, take two copies of the graph, say $(V_1, E_1)$ and $(V_2, E_2)$, and for any marked edge $\{v_i, v_j\}$ in the original graph, add $\{v_{1i}, v_{2j}\}$ and $\{v_{2i}, v_{1j} \}$ to the new graphs (connecting them), then find a path from $s_1$ to $t_2$.
For the cycle-less case, the best I can think of is a solution using max flow: iterate over all marked edges $\{u, v\}$, add a supersource and supersink to the graph, add edges from the supersource to the original source and sink $s$ and $t$, and edges from $u$ and $v$ to the supersink. Then find two vertex disjoint paths from the supersource to the supersink (we consider two paths to be vertex disjoint if the only shared vertices are the supersource and supersink, there are at most two of these paths). If no two paths exist, you cannot use the edge $\{u, v\}$, otherwise you can reconstruct the full path using the flow you found.