Finding a cycle that contains a subset of edges in a graph

230 Views Asked by At

I was wondering about the following problem, but after looking around for a some time I could not find a solution:

Given a directed graph $G = (V, E)$ and a subset $F \in E$, is there a cycle in G that contains each one of the edges in $F$, but possibly not exclusively from $F$ (is there a cycle $C$ so that for any $e \in F$, $e$ is a part of $C$)?

Is this problem easy to solve? I saw two questions that are somehow similar but I couldn't think of a way to use their solutions for this problem - the first is this one which asks a similar question but the result can give any cycle that contains at least one edge from the subset, which is different from this problem (I figured that since there are exponentially many cycles that contain at least one edge of $F$ then there is no simple transformation between the two algorithms).

The second problem that somehow relates is this one that also asks about cycles containing edges from some subset but does not allow for other edges in the graph to be in the cycle.

Obviously it is solvable using a brute force or backtracking algorithm but that seems to be very inefficient (and it is verifiable in linear time, meaning it is in NP).

Is this problem solvable in linear time? polynomial time? or is it in NP and not in P? Also, does the computational complexity change when asking about undirected graphs?