# Longest cycle contained in two cycles

Is the following problem NP-complete? (I assume yes).

Input: $$k \in \mathbb{N},G=(V,E)$$ an undirected graph where the edge set can be decomposed into two edge-disjoint simple cycles (these are not a part of the input).

Question: Is there a simple cycle in $$G$$ with length greater than $$k$$?

Obviously the problem is in NP and the maximum degree in $$G$$ is $$\leq 4$$, but that doesn't seem to help.

• I don't think you're right about "at most 4 paths connecting any pair". See: i.imgur.com/mYL4n1V.png – svinja May 20 '13 at 15:47
• @svinja You are right, I should have said at most 4 pairwise edge disjoint paths exist between any pair of two vertices. – Listing May 20 '13 at 15:53
• Your title is misleading, because the longest simple cycle can be none of the two cycles in the decomposition of $E$ (in any decomposition). – Denis May 22 '13 at 12:00
• @dkuper it can actually, look at the union of two vertex disjoint simple cycles. – Listing May 22 '13 at 12:01
• My point is not that it can never be one of them, it is that sometimes it is not one of them. So the problem is not finding the bigger of the two. – Denis May 22 '13 at 12:43

A reduction attempt ....

Reduction from Hamiltonian path on digraph $G = (V,E)$ with max degree 3 which is NPC [G&J]

• ignore the direction of the edges, and using a first depth (undirected) scan from an arbitrary node, divide the edges of $G$ in two sets of distinct (undirected) paths (red and green in the figures);
• join the red paths adding extra "linking nodes" (purple nodes in the figure B) and make an undirected red circuit; join the green paths adding extra "linking nodes" (purple nodes in the figure) and make an undirected green circuit;
• transform each original node $b \in V$ of indegree 1 and outdegree 2 (figure C), adding $k$ yellow nodes on the inbound red edge $a\to b$, and adding $k$ yellow nodes on the first outbound red edge $b \to c$; finally add $k$ yellow nodes "towards" the second outbound green edge $b \to d$ using a "wrapped" path around $b$ that touches the outermost yellow nodes of the red edges (figure D).

In the resulting graph all the $3k$ yellow nodes can be traversed by a simple path only in the two ways showed in figure E and figure F, which correspond to the two valid traversals of the original node $b \in V$; informally if an edge towards the extra "linking" purple node is used, $k$ yellow nodes cannot be traversed.

• transform each original node of V of indegree 2 and outdegree 1 in a similar way

Picking a large enough $k \gg |V|$, the result graph $G'$ has an simple path of length greater than $3k(|V|-1)$ if and only if the original graph $G$ has an Hamiltonian path (of length $|V|-1$)

• This is a very beautiful proof, maybe you should direct the edges in figure 'A' to make it easier to understand how to get the paths (I think I understood it though). – Listing May 25 '13 at 15:31
• @Listing: the construction of the paths doesn't depend on the directed edges (indeed I wrote "undirected" search in the answer). You should start from an arbitrary node, make a depth first scan from it coloring with red the edges traversed, then backtrack to the first degree 3 node encountered and continue the depth first scan from it coloring with green the edges traversed, and so on ... perhaps it has a more formal definition, but it doesn't come to my mind now. Let me know if you need further details. – Vor May 25 '13 at 18:22
• I see, the property that edges are traversed in the 'correct' direction is enforced by the last transformation. Thank you for the clarification. – Listing May 25 '13 at 18:41

Inspired by Vor's answer, I want to give a simpler one.

Start with Hamiltonian cycle problem for grid graphs problem which was proven hard by Itai.

It can be easily seen that edge set of a grid graph can be partitioned into 2 disjoint subsets: horizontal and vertical.

So now, we need to weave all horizontal ones into one simple cycle, and weave all vertical ones into another simple cycle.

This is very easy task: for vertical ones, sweep from leftmost to rightmost, just connect any vertical gaps, then connect consecutive x-coordinated vertical line, then connect the lowest leftmost vertex with the highest rightmost vertex. Do similarly for horizontal edges.

Note that the obtained graph is still simple, undirected and satisfies requirement. It is simple because at the last steps of vertical phase and horizontal phase, we deal with two different vertex pairs.

Now, do a similar trick as Vor did. At each vertex, for each of its original incident edge, add $$k$$ new vertices. As usual, $$k$$ ahouls be large enough. Lastly, the length of a genuine Hamiltonian cycle should be $$2k|V|$$. But of course, it is not hamiltonian of the obtained graph.