9
Discrete Mathematics 309 (2009) 104–112 www.elsevier.com/locate/disc Two-factors in orientated graphs with forbidden transitions Zdenˇ ek Dvoˇ ak Department of Applied Mathematics, Charles University, Malostransk´ e N´ amˇ est´ ı 25, 118 00 Praha 1, Czech Republic Received 28 September 2003; received in revised form 13 December 2007; accepted 14 December 2007 Available online 30 January 2008 Abstract The instance of the problem of finding 2-factors in an orientated graph with forbidden transitions consists of an orientated graph G and for each vertex v of G, a graph H v of allowed transitions at v. Vertices of the graph H v are the edges incident to v. An orientated 2-factor F of G is called legal if all the transitions are allowed, i.e. for every vertex v, the two edges of F adjacent to it form an edge in H v . Deciding whether a legal 2-factor exists in G is NP-complete in general. We investigate the case when the graphs of allowed transitions are taken from some fixed class C . We provide an exact characterization of classes C so that the problem is NP-complete. In particular, we prove a dichotomy for this problem, i.e. that for any class C it is either polynomial or NP-complete. c 2007 Elsevier B.V. All rights reserved. Keywords: 2-factors; Complexity; Dichotomy 0. Introduction The instance of the studied problem consists of an oriented graph G in that some pairs of edges incident to a vertex are marked as forbidden. The task is to find a 2-factor in G that does not contain such a pair of edges. Since the graphs of forbidden transitions in the graphs we consider are usually quite dense, we rather study graphs with allowed transitions. We first present some definitions in order to formulate the problem exactly: Let Γ be a set of a bipartite graphs with vertices explicitly assigned to the two classes. If H Γ , denote the classes by I ( H ) and O ( H ). The graphs in this set are used to represent the allowed transitions at a vertex. We do not consider edgeless graphs to be members of this set, since excluding them does not affect the complexity of the considered problem. We work with orientated graphs (in some parts of the paper with parallel edges and loops allowed) with allowed transitions at vertices. We say that the transition is forbidden if it is not allowed. In the figures we mark the allowed transitions by solid lines and the forbidden ones by dotted lines. When the transition is not drawn it is irrelevant for the particular construction and we do not care whether it is allowed or forbidden. Sometimes we consider the edges to consist of two half-edges. During some of the constructions, we also allow the half-edges to be dangling (not being part of any edge), and we connect them with a matching half-edge later. A graph is balanced if the number of its dangling in-halfedges is equal to the number of its dangling out-halfedges. E-mail address: [email protected]. 0012-365X/$ - see front matter c 2007 Elsevier B.V. All rights reserved. doi:10.1016/j.disc.2007.12.050

Two-factors in orientated graphs with forbidden transitions

Embed Size (px)

Citation preview

Page 1: Two-factors in orientated graphs with forbidden transitions

Discrete Mathematics 309 (2009) 104–112www.elsevier.com/locate/disc

Two-factors in orientated graphs with forbidden transitions

Zdenek Dvorak

Department of Applied Mathematics, Charles University, Malostranske Namestı 25, 118 00 Praha 1, Czech Republic

Received 28 September 2003; received in revised form 13 December 2007; accepted 14 December 2007Available online 30 January 2008

Abstract

The instance of the problem of finding 2-factors in an orientated graph with forbidden transitions consists of an orientated graphG and for each vertex v of G, a graph Hv of allowed transitions at v. Vertices of the graph Hv are the edges incident to v. Anorientated 2-factor F of G is called legal if all the transitions are allowed, i.e. for every vertex v, the two edges of F adjacentto it form an edge in Hv . Deciding whether a legal 2-factor exists in G is NP-complete in general. We investigate the case whenthe graphs of allowed transitions are taken from some fixed class C . We provide an exact characterization of classes C so that theproblem is NP-complete. In particular, we prove a dichotomy for this problem, i.e. that for any class C it is either polynomial orNP-complete.c© 2007 Elsevier B.V. All rights reserved.

Keywords: 2-factors; Complexity; Dichotomy

0. Introduction

The instance of the studied problem consists of an oriented graph G in that some pairs of edges incident to a vertexare marked as forbidden. The task is to find a 2-factor in G that does not contain such a pair of edges. Since thegraphs of forbidden transitions in the graphs we consider are usually quite dense, we rather study graphs with allowedtransitions. We first present some definitions in order to formulate the problem exactly:

Let Γ be a set of a bipartite graphs with vertices explicitly assigned to the two classes. If H ∈ Γ , denote the classesby I (H) and O(H). The graphs in this set are used to represent the allowed transitions at a vertex. We do not consideredgeless graphs to be members of this set, since excluding them does not affect the complexity of the consideredproblem.

We work with orientated graphs (in some parts of the paper with parallel edges and loops allowed) with allowedtransitions at vertices. We say that the transition is forbidden if it is not allowed. In the figures we mark the allowedtransitions by solid lines and the forbidden ones by dotted lines. When the transition is not drawn it is irrelevant forthe particular construction and we do not care whether it is allowed or forbidden.

Sometimes we consider the edges to consist of two half-edges. During some of the constructions, we also allow thehalf-edges to be dangling (not being part of any edge), and we connect them with a matching half-edge later. A graphis balanced if the number of its dangling in-halfedges is equal to the number of its dangling out-halfedges.

E-mail address: [email protected].

0012-365X/$ - see front matter c© 2007 Elsevier B.V. All rights reserved.doi:10.1016/j.disc.2007.12.050

Page 2: Two-factors in orientated graphs with forbidden transitions

Z. Dvorak / Discrete Mathematics 309 (2009) 104–112 105

For C ⊆ Γ , let M(C) denote the family of orientated multigraphs with allowed transitions belonging to the classC , i.e. each of the vertices of G ∈ M(C) has assigned a graph H of allowed transitions that belongs to C togetherwith a matching between the incoming edges and I (H) and between the outgoing edges and O(H). Similarly, letS(C) be the family of simple orientated graphs (without parallel edges and loops) with allowed transitions belongingto the class C .

For a vertex v ∈ G, let Hv ∈ Γ be the graph of allowed transitions at v. We identify the vertices of Hv with thecorresponding (half)edges of G incident to v in the rest of this paper. Let d+v be the indegree and d−v the outdegreeof v. Note that |I (Hv)| = d+v and |O(Hv)| = d−v . In a significant part of the paper, we focus our attention to graphswhere d+v = d−v for each vertex v, and consequently |I (Hv)| = |O(Hv)| for each graph of allowed transitions. Let Γrbe the set of all bipartite graphs in Γ such that both classes have the same size.

For a graph H ∈ Γ , let H [V ] denote the subgraph of the graph H induced by the set of vertices V . LetO ′(H) = {v ∈ O(H) : (∃e ∈ E(H)) e = {u, v}} and I ′(H) = {v ∈ I (H) : (∃e ∈ E(H)) e = {u, v}} be thesets of vertices of H that are not isolated, and let H = H [I ′(H) ∪ O ′(H)]. Some special subsets of Γ appear inour characterizations and constructions: Let D+ ⊂ Γ be the set of graphs H such that |I ′(H)| ≤ 2. Analogically,D− ⊂ Γ is the class of graphs H such that |O ′(H)| ≤ 2. Let B ⊂ Γ be the set of graphs H such that H is a completebipartite graph.

An orientated 2-factor in a graph G is a subgraph F of G such that for any vertex v ∈ V (G), the indegree andthe outdegree of v in F is exactly one. A 2-factor is legal if it uses only allowed transitions, i.e. for any pair of edgese, f ∈ F that are incident with a vertex v ∈ V (G), {e, f } is an edge of E(Hv).

We consider the complexity of finding a legal orientated 2-factor in a graph G with allowed transitions. In general,this problem is NP-complete (this fact follows from the results of this paper, although a simpler proof probably exists).We study the complexity of this problem restricted to graphs from M(C) (or S(C)) for some fixed class C . In casethat C ⊆ Γr , we prove that if C ⊆ D+ or C ⊆ D− or C ⊆ B, then the problem is solvable in polynomial time, andthat it is NP-complete otherwise.

In the general case (C 6⊆ Γr ), it may happen that M(C) = M(C ∩ Γr ) if either all graphs H ∈ C \ Γr have|I (H)| > |O(H)|, or all of them have |I (H)| < |O(H)|. If one of these conditions is satisfied, the complexity of theproblem depends only on the set C ∩Γr , thus forcing us to be a bit careful when formulating the characterization. Wecall the class C ⊆ Γ simple if the following conditions are satisfied:

• C ∩ Γr ⊆ D+ or C ∩ Γr ⊆ D− or C ∩ Γr ⊆ B, and• if M(C) 6= M(C ∩ Γr ), then C ⊆ D+ or C ⊆ D− or C ⊆ B.

We claim that the problem of finding a 2-factor with allowed transitions is solvable in polynomial time for graphsin the class M(C) (or S(C)) if C is simple, and that it is NP-complete otherwise.

The problem under consideration is inspired by the results of Kratochvıl and Poljak [5]. They study the similarproblem for undirected graphs — in this case, the problem is polynomial if the graphs of allowed transitions are eithercomplete multipartite ones or subgraphs of the cycle of length four, and NP-complete otherwise.

Analogical modifications of standard problems were already studied: Szeider [7] proved the dichotomy result forthe problem of finding a path in graph with forbidden transitions. Interesting structural results on compatible pathsand cycles were derived in context of Eulerian graphs, see for example [4,6].

1. Polynomial cases

Let the size of the graph G (denoted by |G|) be the number of edges of G. Note that we may assume that|V (G)| ≤ |G|, since if G contains a 2-factor, then the indegree and the outdegree of each vertex is nonzero.

Lemma 1. If C ⊆ D+ or C ⊆ D−, or M(C) = M(C ∩ Γr ) and C ∩ Γr satisfies one of these conditions, then theproblem of finding a legal 2-factor for a graph G ∈ M(C) can be solved in time O(|G|2).

Proof. If M(C) = M(C∩Γr ), then no vertex may have a graph in C \Γr assigned as the graph of allowed transitions,hence it suffices to consider the case that C ⊆ D+ or C ⊆ D−. Let us assume C ⊆ D+ (the case C ⊆ D− issymmetrical), and let G be a graph in M(C). We reformulate the problem of finding a 2-factor in G as a 2-SATinstance with O(|G|2) clauses, thus obtaining the desired time bound. We create a variable xe for each edge e of G —we want xe to be true if and only if e belongs to the 2-factor. For edges e, f ∈ E(G), we add the following clauses tothe formula:

Page 3: Two-factors in orientated graphs with forbidden transitions

106 Z. Dvorak / Discrete Mathematics 309 (2009) 104–112

(a) ¬xe, if e = (uv) and e 6∈ I ′(Hv) or e 6∈ O ′(Hu).(b) xe, if e = (uv), e ∈ I ′(Hv) and |I ′(Hv)| = 1.(c) xe ∨ x f and ¬xe ∨ ¬x f , if e 6= f , e = (uv), f = (wv) and I ′(Hv) = {e, f }.(d) ¬xe ∨ ¬x f , if e = (uv), f = (vw), e ∈ I ′(Hv) and {e, f } 6∈ E(Hv).(e) ¬xe ∨ ¬x f , if e 6= f , e = (uv) and f = (uw).

It should be clear that this 2-SAT instance ϕ is satisfiable if and only if there is the sought 2-factor: If there is alegal 2-factor, we may set xe true exactly for edges of the 2-factor and all the clauses are satisfied. On the other hand,given an assignment of variables such that ϕ is satisfied, consider the subgraph F of G consisting of the edges e suchthat xe is true. By (a)–(c), the indegree of every vertex in F is one. By (e), the outdegree of every vertex is at mostone, but since the sum of in- and outdegrees of F is the same, the outdegree must also be exactly one for each vertex.Therefore, F is a 2-factor, and by (d), it respects all the allowed transitions.

For each edge e, the corresponding variable xe is contained in at most 2|G| + 3 clauses, hence the formula ϕ hasO(|G|2) clauses. The 2-SAT problem can be solved in the time linear in the size of the instance, thus we can decidewhether a legal 2-factor exists in G in time O(|G|2). �

Lemma 2. If C ⊆ B, or M(C) = M(C ∩ Γr ) and C ∩ Γr ⊆ B, then the problem of finding a legal 2-factor for agraph G ∈ M(C) can be solved in time O

(|G|√|V (G)|

).

Proof. Similarly to the proof of Lemma 1, we may assume that C ⊆ B. Let G ∈ M(C) be an instance of theconsidered problem.

Note that an edge e = (uv) such that e 6∈ O ′(Hu) or e 6∈ I ′(Hv) cannot belong to a legal 2-factor. Therefore, byremoving all such edges from G, we do not affect the existence of the legal 2-factor. In the resulting graph G ′, alltransitions are allowed, i.e., we have transformed the problem to the task of finding an oriented 2-factor in a graphwithout forbidden transitions. We may even assume that G ′ is simple, as in this case we may suppress parallel edges.

By splitting the vertices of G ′ into input and output parts, we conclude that this problem is equivalent to findinga perfect matching in a bipartite graph. For a graph with n vertices and e edges, it is possible to decide whether itcontains a perfect matching in time O(e

√n) [1,3], hence we can decide whether G contains a legal 2-factor in time

O(|G|√|V (G)|

). �

2. Gadgets

It remains to prove that the problem is NP-complete unless it falls into one of the categories described by Lemmas 1and 2. Since the problem obviously belongs to NP, it suffices to show its NP-hardness. We do this by reduction from

the 3-exact set cover problem. The instance of this problem consists of a pair of sets (P, Q) such that Q ⊆(

P3

)and

each element of P belongs to exactly three sets in Q. The question is whether there exists a set Q′ ⊆ Q such that eachelement of P belongs to exactly one set in Q′. This problem is known to be NP-complete (Garey and Johnson [2]).

For the reduction we need several gadgets (graphs whose legal 2-factors satisfy certain prescribed properties) thatwe develop in the following lemmas. We start with a gadget Z , that we use to turn multigraphs into simple graphs:

Lemma 3. If C ⊆ Γ is not simple, then there exists a graph Z ∈ S(C) with a special edge fZ such that Z has alegal 2-factor containing the edge fZ and a legal 2-factor that does not contain the edge fZ .

Proof. If M(C) = M(C ∩ Γr ), let C ′ = C ∩ Γr , otherwise let C ′ = C . Note that C ′ 6⊆ B, hence there exists a graphH ∈ C ′ such that H contains two disjoint edges t1 and t2.

The construction proceeds as follows: We construct a simple graph Z ′ that has two different legal 2-factors F1 andF2. The graph of the allowed transitions at each vertex of Z ′ belongs to C ′. Some dangling half-edges may be incidentwith Z ′. We construct the graph Z ′ in such a way that it is balanced; let m be the number of the dangling in-halfedges(or out-halfedges) incident with Z ′.

To obtain the graph Z , we take m + 1 copies Z ′0, Z ′2, . . . , Z ′m of Z ′ and for each i = 0, . . . , m, we connect thedangling out-halfedges Z ′i with in-halfedges from mutually distinct copies Z ′j ( j 6= i). The exact matching of thehalf-edges subject to this restriction is arbitrary. We select fZ as an arbitrary edge of Z ′0 that belongs to exactly onethe 2-factors F1 and F2.

Page 4: Two-factors in orientated graphs with forbidden transitions

Z. Dvorak / Discrete Mathematics 309 (2009) 104–112 107

Fig. 1. The gadget for simplifying graphs.

The graph Z is simple, since Z ′ is simple and for each i 6= j , there is exactly one edge from Zi to Z j . The twolegal 2-factors of Z such that exactly one of them avoids the edge fZ are obtained as the union of the 2-factors Fi inall the copies of the graph Z ′, for i ∈ {1, 2}.

We need to find the graph Z ′ with the described properties. Let us consider the graph Z ′′ depicted in Fig. 1 (thevertices of Z ′′ are drawn by big circles, the edges inside the circles correspond to the allowed transitions and theedges outside the circles to the edges of Z ′′). The graph of allowed transitions at each vertex of Z ′′ is H , and theallowed transitions drawn in the figure correspond to the edges t1 and t2. The graph Z ′′ contains two edge-disjointlegal 2-factors (the outer and the inner cycle).

If Z ′′ is balanced (i.e. if H is in Γr ), then we set Z ′ = Z ′′. Otherwise, |I (H)| 6= |O(H)|; this is only possible ifM(C) 6= M(C ∩ Γr ). Let a = |I (H)| and b = |O(H)|, and let us w.l.o.g. assume that a > b. There exists a graphH ′ ∈ C such that |I (H ′)| < |O(H ′)|. Let a′ = |I (H ′)| and b′ = |O(H ′)|. Let Z ′′′ be an orientated triangle such thatthe graph of allowed transitions at each vertex of Z ′′′ is H ′ and all the transitions between the three edges of Z ′′′ areallowed — this is possible, since the edgeless graphs are not included in Γ .

The graph Z ′′ has a − 2 dangling in-halfedges and b − 2 out-halfedges, and the graph Z ′′′ has a′ − 1 danglingin-halfedges and b − 1 out-halfedges. We let Z ′ be the graph consisting of b′ − a′ copies of Z ′′ and a − b copies ofZ ′′′. The graph Z ′ is balanced and contains two different 2-factors, hence it enables us to construct the graph Z asdescribed before. �

Using the gadget Z , we show that parallel edges and loops do not affect the complexity of the considered problem:

Theorem 4. For any set C ⊆ Γ , the problem of finding a legal 2-factor for graphs in M(C) is NP-complete if andonly if the problem of finding a legal 2-factor for graphs in S(C) is NP-complete.

Proof. Since S(C) ⊆ M(C), it suffices to show the implication from left to right. Suppose that the problem for M(C)

is NP-complete. By Lemmas 1 and 2, if C is simple, then P = NP and all nontrivial problems in P are NP-complete.Therefore, let us assume that C is not simple.

For any graph G ∈ M(C) we find a graph G ′ ∈ S(C) such that G has a legal 2-factor if and only if G ′ has a legal2-factor. The graph G ′ is obtained from G in the following way: Let Z ∈ S(C) be the graph constructed in Lemma 3.For every edge e = (uv) ∈ E(G), we add a copy Ze of the graph Z , remove the edges e and fZe = (wz) and add newedges e′ = (wv) and e′′ = (uz) (they also replace the edges e and fZe in the appropriate allowed transitions).

The size of G ′ is (|Z | + 1) times greater than of the size of G and the graph Z does not depend on G, thus thereduction is polynomial. Since Z is simple, G ′ is simple as well, hence G ′ ∈ S(C). If G has a legal 2-factor F , sodoes G ′:

• If e belongs to F , we add both e′ and e′′ to the 2-factor together with the edges of a legal 2-factor of Ze that containsfZe .

• Otherwise, we add the edges of a legal 2-factor of Ze that does not contain fZe .

Finally, if G ′ has a legal 2-factor F ′, then for each e ∈ E(G), either both e′ and e′′ belong to F ′ or neither does,since they form a 2-cut. A legal 2-factor of G consists of the edges e such that e′ belongs to F ′. �

Page 5: Two-factors in orientated graphs with forbidden transitions

108 Z. Dvorak / Discrete Mathematics 309 (2009) 104–112

By this theorem, we do not need to care about the simplicity of the graphs we create later. The graph A constructedin the following lemma is useful for getting rid of dangling half-edges. Note that the special edges of A cannot appearin any 2-factor.

Lemma 5. Let C ⊆ Γ be a set of graphs such that M(C) 6= M(C ∩ Γr ) and C is not simple. Let d =GCD{|I (H)| − |O(H)| : H ∈ C}. Then, there exists a graph A ∈ M(C) with mutually distinct special edgesf 1

A, . . . , f dA such that A has a legal 2-factor, A \ { f 1

A, . . . , f dA } consists of two components A1 and A2 and all edges

f iA lead from A1 to A2.

Proof. By the fundamental properties of GCD, there exist integers t1, . . . , tm and a finite set {H1, . . . , Hm} ⊆ C suchthat

m∑i=1

ti (|I (Hi )| − |O(Hi )|) = d.

For each i = 1 ≤ i ≤ m, if |I (Hi )| = |O(Hi )|, then we may remove the graph Hi from the set without changingthis property. Otherwise, we may w.l.o.g. assume that |I (Hi )| > |O(Hi )|. Since M(C) 6= M(C ∩ Γr ), there exists agraph H ′i ∈ C with |I (H ′i )| < |O(H ′i )|. We can increase the coefficient ti by |O(H ′i )| − |I (H ′i )| and the coefficient at(|I (H ′i )| − |O(H ′i )|) by |I (Hi )| − |O(Hi )| (possibly adding it to the combination if it was not present there before).This operation does not change the value of the sum, and increases the coefficients corresponding to Hi and H ′i .Therefore, we may assume that all the coefficients in the sum are positive.

We let the graph A2 contain ti vertices with the graph of transitions Hi for each i = 1, . . . , m. We connect all thesevertices to a cycle that forms a legal 2-factor and connect the remaining half-edges arbitrarily, leaving d danglingin-halfedges.

Symmetrically, we construct the graph A1 ∈ M(C) that contains a legal 2-factor and has d dangling out-halfedges.We connect the half-edges of A1 and A2 to form the special edges f j

A , for j = 1, . . . , d . �

The gadget N constructed in the following lemma is used to force an edge not to belong to a 2-factor.

Lemma 6. If C ⊆ Γ is not simple, then there exists a graph N ∈ M(C) containing a special edge fN such that

• N has a legal 2-factor, and• N has no legal 2-factor containing the edge fN .

Proof. If M(C) 6= M(C ∩ Γr ), then we use the graph A constructed in Lemma 5, with fN = f 1A. Suppose that this is

not the case, and let C ′ = C ∩ Γr .Let us first assume C ′ contains a graph H with four mutually distinct vertices i1, i2 ∈ I (H) and o1, o2 ∈ O(H)

such that {i1, o1} ∈ H and {i2, o2} 6∈ H . Enumerate the remaining vertices i3, . . . , i|I (H)| of I (H) and o3, . . . , o|I (H)|

of O(H) in an arbitrary order. In this case, the graph N consists of a single vertex with the graph of allowed transitionsH , and of |I (H)| loops connecting ok to ik for each k = 1, . . . , |I (H)|. This graph has a legal 2-factor consisting ofthe edge (o1i1), and the edge f = (o2i2) does not belong to any legal 2-factor.

Let us now consider the case that such a graph does not exist in C ′. Consider a graph H ∈ C ′. Let d = |I (H)| =

|O(H)|. Note that if {u, v} is an edge of H , then H − {u, v} is a complete bipartite graph. If d > 2, then this impliesthat H = Kd,d . If d ≤ 2 and H 6∈ B, then H = 2K2.

Since C is not simple, it follows that C ′ contains both 2K2 and the graph Kd,d for some d > 2. The graph N thenconsists of two vertices u and v, where the graphs of allowed transitions of u and v are 2K2 and Kd,d , respectively.Let {i1

u , o1u} and {i2

u , o2u} be the allowed transitions of u, and let us enumerate the in- and out-halfedges ik

v and okv

(for k = 1, . . . , d) at v in an arbitrary order. The edges of N are (o1ui1

v ), (o2ui2

v ), (o1vi1

u), (o2vi2

u) and loops (okvik

v ) fork = 3, . . . , d. This graph has two legal 2-factors and none of them uses any of the loops (ok

vikv ). Therefore, we can set

fN = (o3vi3

v ). �

We use the gadget N to show that if finding a legal 2-factor for graphs in M(C1) is NP-complete for some set ofgraphs C1 and the graphs in C1 are induced subgraphs of graphs in a set C , then (up to some technical details), theproblem is NP-complete for the graphs in M(C) as well. For a set of graphs C ⊆ Γr , let C∗ denote the set of allnon-edgeless induced subgraphs of the members of C . Note that C∗ ⊆ Γ , but not necessarily C∗ ⊆ Γr .

Page 6: Two-factors in orientated graphs with forbidden transitions

Z. Dvorak / Discrete Mathematics 309 (2009) 104–112 109

Fig. 2. Copy gadget.

Theorem 7. Let C ⊆ Γr be an arbitrary set of graphs. Let C ′ ⊆ C∗ be a finite subset of C∗. If the problem of findinga legal 2-factor is NP-complete for graphs in M(C ′), then it is also NP-complete for graphs in M(C).

Proof. If C is simple, so is C ′, and the problems for M(C ′) and for M(C) are both solvable in polynomial time byLemmas 1 and 2. Therefore, assume that C is not simple and that the problem is NP-complete for M(C ′). For a graphH ′ ∈ C ′, let H ′ be a smallest graph in C such that H ′ is an induced subgraph of H ′.

Suppose we are given a graph G ∈ M(C ′). We find a graph G ′ ∈ M(C) such that G contains a legal 2-factor if andonly if G ′ does. We proceed in the following way: For each vertex v ∈ V (G), let H ′v ∈ C ′ be the graph of allowedtransitions at v. The graph H ′v is an induced subgraph of the graph Hv = H ′v ∈ C . We extend the graph of allowedtransitions at v to Hv , thus creating some dangling half-edges and obtaining an auxiliary graph G ′′. The graph G ′′ isbalanced, as the sum of indegrees is equal to the sum of outdegrees in G and C ⊆ Γr .

Let us pair the dangling in-halfedges with the out-halfedges arbitrarily. Let N ∈ M(C) be the graph obtained inLemma 6. For every pair of half-edges i and o of G ′′, we add a copy Nio of the graph N , remove the edge fNio = (uv)

and connect u to i and o to v instead. Let G ′ be the graph obtained this way.By the properties of the graph N , the edges connecting the copies of N with G ′′ cannot appear in any legal 2-factor

of G ′. Therefore, we may restrict the legal 2-factor of G ′ to G. On the other hand, given a legal 2-factor of G, wecreate a legal 2-factor of G ′ by adding the legal 2-factors inside the copies of the graph N . Therefore, G has a legal2-factor if and only if G ′ has one.

Since C ′ is finite, there exists a constant M = max{|V (H ′)| : H ′ ∈ C ′}. Then the size of G ′ is at most|G| + M · |V (G)| · |N |. Both |N | and M are constants independent on the input graph G, hence this is a polynomialreduction. �

Let us now describe the construction of a “copy” gadget, with special half-edges such that for each legal 2-factorF , either all the half-edges belong to F or none does. A subgraph G ′ ⊆ G covers G if every vertex of G is incidentwith an edge of G ′.

Lemma 8. For any class of graphs C ⊆ Γr such that C 6⊆ B, there exists a finite set CK ⊆ C∗ and a graphK ∈ M(CK ) with three dangling in-halfedges i1

K , i2K and i3

K and three dangling out-halfedges o1K , o2

K and o3K with

the following properties (see Fig. 2(a), (b)):

(i) there exist three vertex-disjoint paths respecting the allowed transitions in K that join ikK to ok

K for k = 1, 2, 3,and the union of these paths covers the vertices of K , and

(ii) there exists a legal 2-factor in K (containing none of the dangling half-edges), and(iii) if K is an induced subgraph of a graph G and G has a legal 2-factor F, then the restriction of F to K is one of

the subgraphs described in (i) or (ii).

Proof. The construction of the graph K is depicted in Fig. 3(a). The graph of allowed transitions at each vertex of Kis the graph H depicted in Fig. 3(b) (i.e. the transitions a1b1 and a2b2 are allowed, the transition a1b2 is forbiddenand the remaining transition a2b1 may or may not be allowed). We let CK = {H}.

Let us first show that a graph H that satisfies this description appears in C∗. Let H1 be a graph in C \ B, and leti ∈ I ′(H1), o ∈ O ′(H1) be arbitrary vertices such that {i, o} 6∈ E(H1). By the definition of I ′ and O ′, there existvertices i ′ ∈ I ′(H1) and o′ ∈ O ′(H1) such that {i ′, o} ∈ E(H1) and {i, o′} ∈ E(H1). We let H be the subgraph of H1induced by {i, i ′, o, o′}.

Finally, let us consider the construction of the graph K . Note that K has the two subgraphs required in (i) and (ii).To prove (iii), suppose that K ⊆ G and let F be a legal 2-factor of G. If none of the edges ik

K belongs to F , then

Page 7: Two-factors in orientated graphs with forbidden transitions

110 Z. Dvorak / Discrete Mathematics 309 (2009) 104–112

Fig. 3. Copy gadget internals.

Fig. 4. One-in-three gadget.

Fig. 5. One-in-three gadget internals.

the restriction of F to K is the 2-factor described in (ii). Therefore, assume w.l.o.g. that i1K ∈ F . Since there is only

one allowed transition from i1K , the half-edge o1

K also belongs to F . Then, the 2-factor F must use i2K to cover its

destination vertex, hence also {i2K , o2

K } ∈ F and similarly {i3K , o3

K } ∈ F . This is the subgraph described in (i). �

The last gadget we need is “one-in-three” one, that serves as a choice between three possible configurations of alegal 2-factor:

Lemma 9. For any family of graphs C ⊆ Γr , unless C is simple there exists a finite set of graphs CJ ⊆ C∗ and agraph and J ∈ M(CJ ) with three dangling in-halfedges i1

J , i2J and i3

J and three dangling out-halfedges o1J , o2

J ando3

J satisfying the following properties, see Fig. 4(a)–(c):

(i) For each x ∈ {1, 2, 3}, there exists a path in J that covers all vertices of J and joins i xJ with ox

J , and(ii) if J is an induced subgraph of a graph G and F is a legal 2-factor of G, then F contains exactly one of the

half-edges {i1J , i2

J , i3J }, and consequently also exactly one of the half-edges {o1

J , o2J , o3

J }.

Proof. If 3K2 is a subgraph of some graph H ∈ C , then we let H ′ be the induced subgraph of H with six verticessuch that 3K2 ⊆ H ′. We set CJ = {H ′} and let J be a single vertex with the graph of allowed transitions H ′, seeFig. 5(a). Exactly one path must go through this single vertex in a legal 2-factor, and all the transitions described in(i) are allowed.

Suppose now that 3K2 is not a subgraph of any graph in C . In this case, we compose the gadget from two partsas depicted in Fig. 5(b). We construct the parts in such a way that they are acyclic. It follows that no component of a2-factor may be contained completely inside J , and since each path through J contains the edge ec, any 2-factor in asupergraph of J must contain exactly one path that covers J , thus the condition (ii) is satisfied.

Depending on the set of graphs of allowed transitions C , we use one of the two ways depicted in Fig. 5(c) and(d) (only the “narrowing” parts are depicted, the widening ones are symmetrical). For the construction in Fig. 5(c),

Page 8: Two-factors in orientated graphs with forbidden transitions

Z. Dvorak / Discrete Mathematics 309 (2009) 104–112 111

we require K3,1 to be a subgraph of a graph in C . For the construction in Fig. 5(d), we need a subgraph H ′′ with fivevertices such that I (H ′′) = {i1, i2, i3}, O(H ′′) = {o1, o2} and {{i1, o1}, {i2, o2}, {i3, o2}} ⊆ E(H ′′). We also needthe graph K2,1, but it is an induced subgraph of H ′′. Note that in both cases, there exists a legal path from any of thein-halfedges to the out-halfedge, hence the construction depicted in Fig. 5(b) also satisfies condition (i).

Finally, let us show that at least one of the graphs 3K2, K3,1 and H ′′ is an induced subgraph of some graph in C .Consider a graph H ∈ C \ D+. Note that |I ′(H)| ≥ 3 and let e1, e2 and e3 be arbitrary edges of H with distinctsources, and let T ⊆ O(H) be the set of vertices incident with e1, e2 or e3. If |T | = 1, then K3,1 ⊆ H , if |T | = 2then H ′′ ⊆ H and finally, if |T | = 3 then 3K2 ⊆ H . �

Note that we do not require that it is not possible to find a covering path through the gadget J that would connecti x

J and oyJ for x 6= y. As we will see later, it suffices to have such a requirement only for the “copy” gadget K .

3. Balanced case

Now we are ready to prove the dichotomy for subclasses of Γr :

Theorem 10. For any set C ⊆ Γr , if C is not simple then the problem of finding a legal 2-factor for a graph fromM(C) is NP-complete.

Proof. Let K and CK ⊆ C∗ be the gadget and the corresponding set of allowed transition graphs constructed inLemma 8 for the set C . Similarly, let J and CJ be the gadget and the set obtained in Lemma 9. Let C ′ = CK ∪ CJ .By Theorem 7, it suffices to show that the problem is NP-complete for graphs from M(C ′). We proceed by reductionfrom the problem of finding an exact set cover where each element is member of exactly three sets and each set has asize of exactly three [2], as mentioned before.

Let (P, Q), where Q ⊆(

P3

), be an instance of the exact set cover problem. We create an equivalent instance

G ∈ M(C ′) of the legal 2-factor problem as follows:For each set q ∈ Q, we include a copy Kq of the graph K , and for each element p ∈ P , we add a copy Jp of graph

J . Let us now describe the way we connect the dangling half-edges of these graphs. The idea behind the constructionis that each special edge of Jp corresponds to an occurrence of p in one of the sets of Q:

Let f1 and f2 be arbitrary functions that map pairs (p, q) with p ∈ q to {1, 2, 3} such that f1(p1, q) 6= f1(p2, q)

if p1 6= p2 and f2(p, q1) 6= f2(p, q2) if q1 6= q2. For each (p, q) such that p ∈ q, we join the half-edges o f1(p,q)Kq

with i f2(p,q)Jp

and o f2(p,q)Jp

with i f1(p,q)Kq

.

If the exact set cover instance has a solution Q′, let F be the subgraph of G obtained in the following way: Ifq ∈ Q′, we add to F the edges of the three covering paths of Kq that use all its special half-edges. Otherwise, weadd the edges of to the 2-factor of Kq that avoids the special half-edges. For each element p, there exists exactly oneq ∈ Q′ such that p ∈ q , thus exactly one in-halfedge i and the matching out-halfedge o of Jp belongs to F . We addthe path joining i with o that covers Jp to F . Observe that F is a legal 2-factor of G.

Conversely, suppose that F is a legal 2-factor of G. By Lemma 8, either all edges adjacent to Kq are in F or noneis, for any q ∈ Q. Let Q′ ⊆ Q be the family of sets q such that the half-edges of Kq belong to F . By Lemma 9(ii),exactly one in-halfedge ia

Jpand exactly one out-halfedge ob

Jpadjacent to Jp belongs to F , and by the properties of K

and the linkage of the edges of G, a = b. Therefore, Q′ is a solution to the considered exact set cover instance.Size of the graph G is O(|P‖J | + |Q‖K |), i.e. it is polynomial in the size of (P, Q). Therefore, this reduction is

polynomial and we conclude that the problem of finding a legal 2-factor for a graph in M(C ′) is NP-complete. �

By combining Theorems 4 and 10, we immediately obtain the following:

Corollary 11. If a set C ⊆ Γr is not simple, then the problem of finding a legal 2-factor for a graph from S(C) isNP-complete.

4. General case

Let us now consider the general case, where the graphs of allowed transitions are not necessarily balanced.

Page 9: Two-factors in orientated graphs with forbidden transitions

112 Z. Dvorak / Discrete Mathematics 309 (2009) 104–112

Theorem 12. If a set C ⊆ Γ is not simple, then the problem of finding a legal 2-factor for a graph from S(C) isNP-complete.

Proof. By Theorem 4, it is enough to prove NP-completeness of the problem for M(C). If M(C) = M(C ∩Γr ), thenwe apply Theorem 10 for the set C ∩ Γr ; therefore, we may assume that M(C) 6= M(C ∩ Γr ).

Let C ′ ⊆ Γr be the set of graphs that are obtained from graphs in C by padding the smaller partition by verticeswith no allowed transitions. Because C is not simple, C ′ is not simple, hence the problem of finding a legal 2-factorfor a graph from S(C ′) is NP-complete by Corollary 11. Let G ∈ S(C ′) be an instance of this problem. Let N ∈ M(C)

be the graph constructed in Lemma 6, and A1 and A2 the two parts of the graph A ∈ M(C) constructed in Lemma 5.We create a graph G ′ ∈ M(C) from G by this procedure: we remove the padding, restricting the graphs of allowed

transitions to the corresponding graphs in C . This procedure may leave some dangling half-edges incident with thevertices of graphs of allowed transitions in C , and the resulting graph does not have to be balanced. As long as thereexist an in-halfedge i and an out-halfedge o, we add copy of the graph N , split the edge fN and connect the half-edgesthrough this copy of N . This ensures that these half-edges do not belong to a legal 2-factor. W.l.o.g., suppose that wehave only dangling in-halfedges left. Let d = GC D{|I (H)| − |O(H)| : H ∈ C}. Note that the number of danglingin-halfedges is divisible by d . Let us split the dangling in-halfedges into d-tuples arbitrarily. For every d-tuple, weadd a copy of graph A1 and connect the in-halfedges with the dangling out-halfedges of A1.

If G ′ has a legal 2-factor, we obtain a legal 2-factor of G by restricting it to G. If G has a legal 2-factor F , it doesnot contain any edge incident to the padding, as there are no allowed transitions. Therefore, we may extend it to alegal 2-factor of G ′ by adding legal 2-factors to the copies of A1, A2 and N .

Note that the size of the graph G ′ is at most O(max(|A| + 1, |N | + 1)|G|), hence this indeed is a polynomialreduction, and we conclude that the problem of finding a legal 2-factor for a graph in M(C) is NP-complete. �

Acknowledgements

I would like to thank Jan Kratochvıl and Jan Kara for bringing my attention to the problem and for usefuldiscussions. I am also grateful to the anonymous referee for his patience with reading an earlier version of the paperand providing valuable suggestions for improvements of the presentation.

References

[1] J. Hopcroft, R. Karp, An n5/2 algorithm for matching in bipartite graphs, SIAM J. Comput. 2 (4) (1975) 225–231.[2] M.R. Garey, D.S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness, W.H. Freeman, New York, 1979.[3] S. Micali, V.V. Vazirani, An O(

√|V ||E |) algorithm for finding maximum matching in general graphs, in: Proceedings of the 21st Annual

Symposium on Foundations of Computer Science, FOCS, 1980, pp. 17–27.[4] H. Fleischner, Eulerian Graphs and Related Topics, Part 1, Volume 1, in: Annals of Discrete Mathematics, vol. 45, Elsevier Science Publishers,

North-Holland, Amsterdam, 1990.[5] J. Kratochvıl, S. Poljak, Compatible 2-factors, Discrete Appl. Math. 36 (1992) 253–266.[6] J. Maxova, J. Nesetril, Complexity of compatible decompositions of Eulerian graphs and their transformations, in: Proceedings of the 10th

Annual European Symposium on Algorithms, 2002, pp. 711–722.[7] S. Szeider, Finding paths in graphs avoiding forbidden transitions, Discrete Appl. Math. 126 (2–3) (2003) 239–251.