Journal of Algorithms 33, 124᎐139 Ž1999. Article ID jagm.1999.1041, available online at http:rrwww.idealibrary.com on
A Polynomial Time Algorithm for Finding a Cycle Covering a Given Set of Vertices in a Semicomplete Multipartite Digraph Anders Yeo Department of Mathematics and Computer Science, Odense Uni¨ ersity, Denmark Received August 5, 1998; revised June 15, 1999
The existence of a polynomial time algorithm for finding a cycle covering a given set of vertices in a semicomplete multipartite digraph Žif it exists. was conjectured by J. Bang-Jensen, G. Gutin, and A. Yeo. The analog problem for semicomplete bipartite digraphs was conjectured by J. Bang-Jensen and Y. Manoussakis. We prove the conjecture of Bang-Jensen et al. in the affirmative, which also implies the second conjecture. We, furthermore, give a polynomial time algorithm to find a cycle covering a given set of vertices in a semicomplete bipartite digraph, which is the longest of all such cycles, and we conjecture that such an algorithm also exists for semicomplete multipartite digraphs. 䊚 1999 Academic Press
1. INTRODUCTION A semicomplete multipartite digraph ŽSMD. is a digraph D s Ž V Ž D ., AŽ D .. for which the vertices of V Ž D . can be partitioned into a number, k G 2, of subsets Žcalled color classes. such that every pair of vertices from the same color class are nonadjacent and every pair of vertices from different color classes are adjacent Ži.e., there is at least one arc between them.. Two well known special cases are semicomplete digraphs Žwhen k s < V Ž D .<. and semicomplete bipartite digraphs Žwhen k s 2., which is abbreviated to SBD. It is well known Žsee w8x. that there is a cycle including a set of vertices in a semicomplete digraph, of order n, if and only if the vertices lie in the same strong component. Furthermore, we can in O Ž n2 . time Žsee w15x. find a cycle including all the vertices of such a strong component. This implies that we in O Ž n2 . time can find a cycle covering a given set of vertices in a semicomplete digraph Žif it exists. and which is the longest of all such cycles. 124 0196-6774r99 $30.00 Copyright 䊚 1999 by Academic Press All rights of reproduction in any form reserved.
ALGORITHMS FINDING CYCLES
125
Bang-Jensen and Manoussakis w5x conjectured that there was a polynomial time algorithm to find a cycle covering a given set of vertices in a SBD. In this paper we prove two generalizations of this conjecture: Ž1. There is a O Ž< V Ž D .< 5 . time algorithm which finds a cycle covering a given set of vertices in a SBD, D, Žif it exists. and which is the longest of all such cycles; Ž2. There is a O Ž< V Ž D .< 5 . time algorithm which finds a cycle covering a given set of vertices in a SMD. In w4x it is conjectured that there is a polynomial time algorithm for finding a cycle covering a given set of vertices in a SMD, which we therefore also prove in the affirmative. To prove the existence of such algorithms, we use the main result from w18x by Yeo, which in turn uses the results from w2x by Bang-Jensen, Gutin, and Huang. The main result obtained in w18x has many other nice consequences. Every diregular SMD is Hamiltonian. If the size of the largest independent set in a k-strong SMD D is at most 2 k and D has a spanning cycle subgraph Ži.e. a spanning collection of vertex disjoint cycles., then D is Hamiltonian. Any set of k vertices in a k-strong SMD lie on a common cycle. See, furthermore, w3, 4x for other applications of w18x. In w4x Bang-Jensen, Gutin, and Yeo prove the existence of a polynomial time algorithm for finding a Hamiltonian cycle in a SMD Žif it exists.. This algorithm is much more complicated and was discovered several years later than the equivalent polynomial time algorithm for SBD Žsee w10, 11, 14x.. In w4x the following conjecture is stated. CONJECTURE 1.1 w4x. If D is a SMD, then there are polynomial time algorithms for the following problems: Ž1. Gi¨ en set X : V Ž D . find a cycle co¨ ering X. Ž2. Construct a longest cycle in D. Ž3. Gi¨ en set X : V Ž D . find a cycle containing the maximum number of ¨ ertices from X. Conjecture 1.1Ž1. is proven to be true in this paper. Conjecture 1.1Ž2. was proved for SBD’s in w12, 13x but is still open for SMD’s. Conjecture 1.1Ž3. is still open for SBD’s and, therefore, also for SMD’s. We state the following conjecture in this paper. CONJECTURE 1.2. If D is a SMD and X : V Ž D ., then there is a polynomial time algorithm for finding a cycle co¨ ering X Ž if it exists. and which is the longest of all such cycles. In this paper we prove Conjecture 1.2 for the more restricted class of SBD’s, which gives support for Conjecture 1.2. A digraph is called quasi-transitive if for any triple x, y, z of distinct vertices of D, such that xy and yz are arcs of D, there is at least one arc from x to z or from z to x. The O Ž< V Ž D .< 5 . time bound found in this
126
ANDERS YEO
paper is identical to the time bound found for equivalent algorithms for quasi-transitive digraphs. In w1x Bang-Jensen and Gutin, give an O Ž< V Ž D .< 5 . time algorithm for verifying whether a quasi-transitive digraph has a longest cycle through a given set of vertices Žthey actually prove a more general result..
2. TERMINOLOGY AND PRELIMINARIES We shall assume that the reader is familiar with the standard terminology on digraphs and refer the reader to w8x for terminology not discussed here. In this section, D denotes a digraph, x and y are distinct vertices of D, X and Y are disjoint sets of vertices in D, and Q and R are vertex disjoint subgraphs of D. Every cycle and path is assumed simple and directed. A k-path cycle subgraph F of D is a collection of k paths P1 , P2 , . . . , Pk and a number of cycles Z1 , Z2 , . . . , Z s in D Ž s G 0., all vertex disjoint. We shall write F s P1 j P2 j ⭈⭈⭈ j Pk j Z1 j Z2 j ⭈⭈⭈ j Z s Žwe always list the paths before the cycles.. An Ž X, Y .-maximal k-path-cycle subgraph, F, is a k-path-cycle subgraph, where X : V Ž F . and < Y l V Ž F .< G < Y l V Ž F X .< for all k-path-cycle subgraphs, F X , with X : V Ž F X .. A cycle subgraph is a 0-path-cycle subgraph. If F s C1 j C2 j ⭈⭈⭈ j Ct is a cycle subgraph and CU is a cycle with V Ž CU . l V Ž F . s ⭋, then F j CU denotes the cycle subgraph C1 j C2 j ⭈⭈⭈ j Ct j CU . Furthermore, we shall say that CX g F, if CX is a cycle in the cycle subgraph F. If there is an arc from x to y, then we say that x dominates y and write x ª y. We write X ª Y if x ª y for every pair x g X, y g Y of adjacent vertices. If X ª Y, then there may be a pair x g X, y g Y such that both x ª y and y ª x. We write X « Y Ž X strongly dominates Y . if there is no arc from Y to X Žnote that there may be nonadjacent vertices, x g X and y g Y, even if X « Y .. A path starting at x and terminating at y is an Ž x, y .-path. An Ž x, y .-path P is a Ž Q, R .-path if x g V Ž Q ., y g V Ž R ., and V Ž P . l Ž V Ž Q . j V Ž R .. s x, y4 . Let F be a subgraph of D containing both Q and R. A Ž Q, R .F -path P is a Ž Q, R .-path with < V Ž P . l V Ž F .< s 2. D is strongly connected Žor just strong . if there exists an Ž x, y .-path in D for every ordered pair of distinct vertices x, y4 of D. If P is a path containing a subpath from x to y we let P w x, y x denote that subpath. Similarly, if C is a cycle containing vertices x and y, C w x, y x denotes the subpath of C from x to y. D ² Q : is the subgraph induced by the vertices in Q. We define D y X, to be the digraph D ² V Ž D . y X :. If
ALGORITHMS FINDING CYCLES
127
C is a cycle in D, then we shall say that C is X-¨ alid, if and only if < V Ž C . l X < G 1. If F is a subgraph in D, then we shall say that F co¨ ers X if X : V Ž F .. Let C be a cycle containing the vertex x and the vertex set X Žnote we Ž xy . denotes the only allow C to be a cycle, not a path.. Then xq C C q 4 successor Ž predecessor, resp.. of x on C. Moreover, XC s xq C: xgX , y 4 Xy s x : x g X . When the cycle C is determined from the context, we C C shall usually omit the subscript C. Semicomplete multipartite digraphs ŽSMD’s. and semicomplete bipartite digraphs ŽSBD’s. were described in the introduction. If x is a vertex in a SMD, then V c Ž x . will denote the color class Ži.e. maximal independent set. to which x belongs. We conclude this section with the following definition. DEFINITION 2.1. Let D be a digraph and let X, Y, W, Q be sets of vertices. An Ž X, Y, W, Q .- path-cycle subgraph in D, is a Ž X, Y .-maximal 1-path-cycle subgraph, F s p1 p 2 ⭈⭈⭈ pl j C1 j C2 j ⭈⭈⭈ j Ct , of D, such that p1 g W and pl g Q.
3. PRELIMINARY RESULTS LEMMA 3.1. Let D be a digraph and let X : Y : V Ž D .. In O Ž< V Ž D .< 3 . time, we can determine if a Ž X, Y .-maximal cycle subgraph exists in D and find it if it does. Proof. We construct the bipartite graph, GX s Ž V X , EX ., with vertex set V s ¨ 1 , ¨ 2 , ¨ 3 , ¨ 4 : ¨ g V Ž D .4 , and edge set AX s x 1 x 2 , x 2 x 3 , x 3 x 4 : x g V Ž D .4 j x 4 y 1: xy g AŽ D .4 . Let n s < V Ž GX .< s 4 < V Ž D .<. Now define the cost-function, c on the edges of GX , such that cŽ x 1 x 2 . s cŽ x 3 x 4 . s 0 for all x g V Ž D ., cŽ x 2 x 3 . s n for all x g X, cŽ x 2 x 3 . s 1 for all x g Y y X and cŽ x 2 x 3 . s 0 for all x g V Ž D . y Y. Furthermore, let cŽ x 4 y 1 . s 0 for all xy g AŽ D .. Let M be a perfect matching in GX Žsuch a matching exists, for example x 1 x 2 , x 3 , x 4 : x g V Ž D .4 and define the vertex set V U s x: x 2 x 3 g M 4 and arc set AU s xy: x 4 y 1 g M 4 , in D. Observe that if x f V U , then x 1 x 2 , x 3 x 4 4 : M, so there is no arc entering or leaving x in the arc set AU . Similarly, if x g V U then there is precisely one arc entering x and one arc leaving x in AU . Therefore, AU induces a cycle subgraph, F , and the weight of M is < X l V Ž F .< n q <Ž Y y X . l V Ž F .<. If F is a cycle subgraph in D, then M X s x 1 x 2 , x 3 , x 4 : if x f V Ž F .4 j y4 x 1 , x 2 x 3 : if yx is an arc in F 4 is a perfect matching in GX , with weight w s < X l V Ž F .< n q <Ž Y y X . l V Ž F .<. Therefore there is a perfect X
128
ANDERS YEO
matching, M, in GX , with weight w, if and only if there is a cycle subgraph, F , in D, such that w s < X l V Ž F .< n q <Ž Y y X . l V Ž F .<. We can find a maximum weight perfect matching in GX , in O Ž n3 . time using the algorithm described from page 550, in w17x Žusing the comments on page 497 in w17x.. Assume that the maximum weight perfect matching in GX has weight w. If w - < X < n then there is no cycle subgraph which covers X, in D, and if w G < X < n then there is a cycle subgraph, F , in D, such that X : V Ž F . and <Ž Y y X . l F < s w y < X < n. This implies that we can find the desired cycle subgraph in O Ž< V Ž D .< 3 . time. LEMMA 3.2. Let D be a digraph; let X, Y, W, Q be sets of ¨ ertices, with X : Y. In O Ž< V Ž D .< 3 . time, we can determine if a Ž X, Y, W, Q .-path-cycle subgraph exists in D and find it if it does. Proof. Let DX s Ž V X , AX . be the digraph with vertex set V X s V Ž D . j z 4 and arc set AX s AŽ D . j qz: q g Q4 j zw: w g W 4 . Now use Lemma 3.1 to find a cycle subgraph, F, in DX , such that X j z 4 : V Ž F . and <Ž Y j z 4. l V Ž F .< is maximum. We now obtain the desired 1-path-cycle subgraph, by deleting z from F. Note 3.3. We shall assume that all the cycles found in both Lemma 3.1 and Lemma 3.2 are Y-¨ alid, as we otherwise just delete all cycles which do not contain any ¨ ertices from Y Ž and therefore from X ..
4. Ž X, Y .-SINGULAR SUBGRAPHS Recall that the superscripts q and y are only used on cycles, not on paths. The following theorem is a simple version of the main result of w18x. THEOREM 4.1 w18x. Let D be a SMD and let F X s C1X j C2X j ⭈⭈⭈ j CtX be a cycle subgraph in D. There exists an algorithm Ž called singular Ž D, F X .. which, gi¨ en F X and D in O Ž< V Ž D .< 3 . time returns a tuple Ž F, C, ., where F is a cycle subgraph in D Ž possibly F s ⭋., C is a cycle in D y V Ž F . and is a color class, such that y4 Ži. For all Ž F, C .-paths, P s p1 p 2 ⭈⭈⭈ pl , we ha¨ e pq : . 1 , pl X X U Žii. For e¨ ery cycle Ci g F there exists a cycle C g F j C such that V Ž CiX . : V Ž CU .. Žiii. For e¨ ery cycle CU g F j C we ha¨ e V Ž CU . l V Ž F X . / ⭋.
Živ. V Ž F X . : V Ž F j C .. Žv. For e¨ ery cycle V U g F j C, there exists a cycle CiX g F X such that X V Ž Ci . : V Ž CU ..
ALGORITHMS FINDING CYCLES
129
It is an easy exercise to show that Živ. and Žv. follow immediately from Žii. and Žiii. in the above theorem. However, we state Živ. and Žv. for convenience of further references. All five statements can furthermore be seen immediately from the construction of the algorithm singular in w18x. DEFINITION 4.2. Let D be a SMD and let X : Y : V Ž D . be arbitrary. A cycle subgraph, F s C1 j C2 j ⭈⭈⭈ j Ct , is called Ž X, Y .-singular, if it is Ž X, Y .-maximal and the following holds Žgiven the ordering of the cycles.: Ži. For all i g 1, 2, . . . , t y 14 , there exists a color class i R , such y4 that for all Ž C j , Ci .F -paths, P s p1 p 2 ⭈⭈⭈ pl , with j ) i, we have pq 1 , pl R : i . Žii. For all i g 1, 2, . . . , t y 14 , where Vi s V Ž C1 j C2 j ⭈⭈⭈ j Ci ., there is no Ž X y Vi , Y y Vi .-maximal 1-path-cycle subgraph, F X s pX1 pX2 ⭈⭈⭈ pXl j C1X j ⭈⭈⭈ j CtXX , in D y Vi , such that i R l V Ž Ci . « pX1 , pX1 f i R , Ž i R l V Ž Ci ..q£ pXl and < Y l Ž V Ž F X . j Vi .< G < Y l V Ž F .<, where i R is defined in Ži.. THEOREM 4.3. Let D be a SMD, let X : Y : V Ž D . be arbitrary and let F s C1 j C2 j ⭈⭈⭈ j Ct be a Ž X, Y .-singular cycle subgraph. Let the ordering of the cycles be as in Definition 4.2. Then for all j g 2, 3, . . . , t 4 there exists a color class jL , such that for all Ž C j , Ci .F -paths, P s p1 p 2 ⭈⭈⭈ pl , with y4 j ) i, we ha¨ e pq : jL and pq 1 , pl 1 g Y. Proof. Let P s p1 p 2 ⭈⭈⭈ pl be any Ž C j , Ci .F -path, with j ) i, and let iXR . be defined as in Definition 4.2Ži. for all iX s 1, 2, . . . , t y 1. Clearly V c Ž pq 1 R q . s V c Ž py s . Assume that p f Y and define the path R s l i 1 R x Ž. C j w pqq 1 , p 1 p 2 p 3 ⭈⭈⭈ p ly1 . Observe that by Definition 4.2 i we get i l R. V Ž Ci . « V Ž C j ., pqq f i R Žas pq and ply1 ª pl g Ž i R l 1 1 g i q Ž .. Ž . Ž . Ž V Ci . Since X l V C j : Y l V C j : V R . we observe that the 1path-cycle subgraph R j Ž Ciq1 j Ciq2 j ⭈⭈⭈ j Ct y C j ., contradicts Defic Ž y. . nition 4.2Žii.. Therefore, we have shown that V c Ž pq pl s i R and 1 sV q p1 g Y. Let jL s i R , and let Q s q1 q2 ⭈⭈⭈ qm be an arbitrary Ž C j , CiX .F -path, with j ) iX . Clearly, we are done if we can show that iXR s i R , since by c Ž y. . the above arguments this would imply that V c Ž qq qm s iXR s i R 1 sV L q R R X s j and q1 g Y. So assume that i / i for the sake of contradicŽ . tion. Clearly, i / iX , so assume w.l.o.g. that i - iX . Observe that qy m « V Cj q Ž y q Ž Ž . Ž .. X and V Ci « q1 by Definition 4.2 i , which implies that qm ª p1 as q Ž c Ž y. R R c Ž q.. ... X qy p1 and qyy as qq qm / V c Ž qyy m g i / i s V m ª q1 1 gV m y q yy x w q w x w x X The path R s qm C j p1 , q1 QCi qm , qm C j q1 , p1 p 2 p 3 ⭈⭈⭈ ply1 , therey R Ž fore exists. By Definition 4.2Ži. we obtain V Ž Ci . l i R « qy as m , qm f i y R R R q qm g iX / i . and ply1 ª pl g Ž i l V Ž Ci .. . Since, furthermore, X l V Ž Ci j CiX . : Y l V Ž Ci j CiX . : V Ž R ., we observe that the 1-path cy-
130
ANDERS YEO
cle R j ŽŽ Ciq1 j Ciq2 j Ct . y CiX y C j ., contradicts Definition 4.2Žii.. We have therefore shown that iXR s i R , which completes the proof. We conclude this section with Theorem 4.4. THEOREM 4.4. Let D be a SMD and let X : Y : V Ž D . be arbitrary. If there is a cycle subgraph co¨ ering X, then we in O Ž< V Ž D .< 4 . time can find a Ž X, Y .-singular subgraph in D. As the proof of Theorem 4.4 requires an algorithm, we will first describe this algorithm and give a lemma before we complete the proof of Theorem 4.4. The algorithm consists of the following three steps: Input: We are given a SMD, D, and vertex sets X : Y : V Ž D .. Step 1. Use Lemma 3.1 to find a Ž X, Y .-maximal cycle subgraph, F in , in D. If no such F in exist then stop the algorithm. Let i s 1, k max s < Y l V Ž F in .< and F out s ⭋. Step 2. Define Ži. Ž Fi , Ci , i R . s singular Ž D y V Ž F out ., F in . using Theorem 4.1. Žii. Hi s V Ž F out j Ci . Žiii. W s w: i R l V Ž Ci . « w and w g V Ž D . y Hi y i R 4 Živ. Q s q: Ž i R l V Ž Ci ..q£ q and q g V Ž D . y Hi 4 X X Step 3. LetX F out s F out , F in s F in , HiX s Hi , FiX s Fi , CiX s Ci , and i R s i R. If Fi s ⭋, then stop the algorithm and return the cycle subgraph R F out j Ci , and the color classes 1R , 2R , . . . , iy1 . X X Ž ␣ . If a Ž X y Hi , Y y Hi , W, Q .-path-cycle subgraph, P j F U , exists in V Ž D . y HiX , with < Y l Ž HiX j V Ž P j F U ..< G k max Žuse Lemma 3.2.: Let P s p1 p 2 ⭈⭈⭈ pl . Since pl g Q there exists a vertex x g i R l V Ž CiX ., such that pl ª xq. As p1 g W the cycle CU s CiX w xq, x x Pxq exists. Now let F in s CU j F U and go to step 2. X Ž  . Otherwise: Let F in s FiX , F out s F out j CiX , and i s i q 1 and go to step 2. This was the desired algorithm. The algorithm would also work if we deleted the first line in Step 3 and changed the notation accordingly. However, this would also complicate the notation in the proofs. Before we prove that the algorithm has the desired properties, we need the following lemma. After Step 2 the following holds:
LEMMA 4.5.
Ža. V Ž F j F in . : V Ž F out j Ci j Fi . : Hi j V Ž Fi .. Žb. X : V Ž F out j F in . and < Y l V Ž F out j F in .< s k max . out
ALGORITHMS FINDING CYCLES
131
Žc. X : V Ž F out j Ci j Fi . and < Y l V Ž F out j Ci j Fi .< s k max . Žd. For all Y-¨ alid cycles, C ¨ , in D y Hi , and all Ž C ¨ , Ci .-paths, R Ž . P s p1 p 2 , . . . , pl , in D y V Ž F out ., we ha¨ e py l g i l V C i . Furthermore, R ¨ we ha¨ e i l V Ž Ci . « V Ž C .. Proof of Ža.. This follows immediately from Theorem 4.1Živ.. Proof of Žb.. We will prove Žb. by induction. Clearly Žb. is true when we have executed Step 2 for the first time, as then X : F in , < Y l V Ž F in .< s k max and F out s ⭋. If we entered Step 2 from Ž ␣ ., then V Ž F out j F in . s V Ž F out j CU j U F . s V Ž F out j CiX j P j F U . s HiX j V Ž P j F U .. This, together with the maximality of k max , implies that < Y l V Ž F out j F in .< s k max . Since X y HiX : V Ž P j F U ., we obtain X : HiX j V Ž P j XF U . s VX Ž F out j F Xin .. If we entered Step 2 from Ž  ., then V Ž F out . l F in . : V Ž F out j CiX j X Fi . s V Ž F out j F in . Žby Ža... The induction hypothesis and the maximality of k max , now imply Žb.. Proof of Žc.. This follows immediately from Ža., Žb., and the maximality of k max . Proof of Žd.. Let C ¨ be a Y-valid cycle in D y Hi , and let P s p1 p 2 ⭈⭈⭈ pl be a Ž C ¨ , Ci .-path in D y V Ž F out .. If there is no Ž Fi , p1 .-path in D y Hi , then V Ž C ¨ . l V Ž Fi . s ⭋, since if there is a vertex in V Ž C ¨ . l V Ž Fi ., then following C ¨ we obtain a path to p1 in D y Hi . Now F Y s F out j Ci j Fi j C ¨ is a cycle subgraph in D, with < Y l V Ž F Y .< s k max q < Y l V Ž C ¨ .< ) k max Žby Žc. and the fact that C ¨ is a Y-valid cycle.. This is a contradiction against the maximality of k max . Therefore there is a Ž Fi , p1 .-path, Q s q1 q2 ⭈⭈⭈ qm p1 , in D y Hi . Now QP is a walk Ži.e. a not necessarily simple path. from Fi to Ci ending in pl . Therefore there exists a Ž Fi , Ci .-path Žsimple. in D y V Ž F out ., which R Ž . ends in pl . By Theorem 4.1Ži. we obtain that py l g i l V Ci . To prove the second part of Žd., assume that this is false and that there exists a x g V Ž C ¨ . and a y g i R l V Ž Ci . such that x ª y. This is, however, a contradiction against the first part, since yyf i R. Proof of Theorem 4.4. If the algorithm terminates in Step 1, then there is clearly no Ž X, Y .-singular cycle subgraph in D. If the algorithm terminates in Step 3, then let the output be F s C1 j C2 j ⭈⭈⭈ j Ct , and R Žthe cycle subgraph and color classes, respectively.. By Lemma 1R , . . . , ty1 4.5Žc., we obtain that F is Ž X, Y .-maximal. We will now show that Ži. and Žii. in Definition 4.2 hold, which implies that F is Ž X, Y .-singular. Assume for the sake of contradiction that Žii. is false, and that there is a 1-path-cycle F X s P X j C1X j ⭈⭈⭈ j CtXX and an integer i, as described in Žii.. Let P X s pX1 pX2 ⭈⭈⭈ pXl and observe that just before we enter Ž  . in Step 3,
132
ANDERS YEO
with the value i, we have pX1 g W and pXl g Q. It is now an easy exercise to check that F X would imply that the algorithm would enter Ž ␣ . and not Ž  . in Step 3, which is a contradiction. Therefore Žii. holds. We will now show that Ži. holds. Let P s p1 p 2 ⭈⭈⭈ pl be a Ž C a , Cb .F -path, with a ) b. When we enter Ž  . with the value i s b, Lemma 4.5Žd. R implies that py l g b , as C a is a Y-valid cycle in D y H b . Assume for the R w q x sake of contradiction that pq 1 f b . Let Z s C a p 1 , p 1 p 2 p 3 ⭈⭈⭈ p ly1 , R which is a path. Observed that b l V Ž Cb . « pq , by Lemma 4.5Žd.. 1 R Furthermore, ply1 ª pl g Ž bR l V Ž Cb ..q and pq f , which implies 1 b that the 1-path-cycle subgraph Z j ŽŽ Cbq 1 j Cbq2 j ⭈⭈⭈ j Ct . y C a . is a contradiction against Žii.. Therefore Ži. holds. We now only need to prove the O Ž< V Ž D .< 4 . time bound to complete the proof of Theorem 4.4. Let A s < Hi < just after we have performed Step 2 for the th time. We will now show that A ) Ay1 for all values of G 2. If we executed Ž  . in the Ž y 1.th X iteration of Step 3, then A s < Hi < s < V Ž F out j Ci .< ) < V Ž F out .< s < V Ž F out j CiX .< s Ay1. If we executed Ž ␣ . in the Ž y 1X .th iteration of Step 3, then after the th iteration of Step 2, we have F out s F out and V Ž CiX . ; V Ž CU . : V Ž Ci ., because of the following. It is easily seen that V Ž CiX . ; V Ž CU ., so assume that V Ž CU . V Ž Ci . for the sake of contradiction. Theorem 4.1Žii., implies that V Ž CU . l V Ž Ci . s ⭋. By X Theorem 4.1Žv. and Note 3.3, we get that Ci is Y-valid in D y Žd., we get that x « V Ž Ci ., where x is V Ž F out j CiX .. By Lemma 4.5 X defined in Ž ␣ . Žsince x g i R .. Let q g V Ž Ci . y V c Ž x ., and assume w.l.o.g. that V c Ž qy. / V c Ž xq. , since otherwise V c Ž qy. s V c Ž xq. / V c Ž x . and V c Ž qyy . / V c Ž qy. s V c Ž xq. . Now the arstence of arc x ª q is a contradiction against Theorem 4.1Ži.. We have now shown that V Ž CiX . ; V Ž CU . : V Ž Ci .. This implies that A ) Ay1. Since 0 F A F < V Ž D .<, we can at most execute Steps 2 and 3, O Ž< V Ž D .<. times. Since one iteration of Steps 2 and 3 can be done in O Ž< V Ž D .< 3 . time, we have now proven the desired time bound.
5. F-CANONICAL CYCLES We begin this section with a definition Žsee Fig. 1.. DEFINITION 5.1 w4x. Let D be a digraph and F s C1 j C2 j ⭈⭈⭈ j Ct be a cycle subgraph in D. Let R s C1 j C2 j ⭈⭈⭈ j Cty1 and let W s w g V Ž Ct .: ᭚Ž Ct , R .-path in D starting at w4 . A cycle C, in D, is called F-canonical if C can be written as q q C s C t wq 1 , w 2 P1 C t w 2 , w 3 P2 ⭈⭈⭈ Pmy1 C t wm , w 1 Pm ,
Ž 1.
ALGORITHMS FINDING CYCLES
133
FIG. 1. An example of an F-canonical cycle for some cycle subgraph F s C1 j ⭈⭈⭈ j Ct . x Each Pi is a path in D y V Ž Ct . and each Q i is a path of the form Q i s Ct w wq i , wiq1 , all X ei , ei.
where w 1 , w 2 , . . . , wm 4 : W and Pi is a path in D y V Ž Ct ., with V Ž Pi l R . / ⭋ Žfor i s 1, 2, . . . , m.. LEMMA 5.2. Let D be a SMD and let X : Y : V Ž D ., such that either Y s X or D is a SBD and Y s V Ž D .. Let F s C1 j C2 j ⭈⭈⭈ j Ct , t G 2, be an Ž X, Y .-singular subgraph in D, and let tL be defined as in Theorem 4.3. Let also R s C1 j ⭈⭈⭈ j Cty1 and W s w g V Ž Ct .: ᭚Ž Ct , R .-path in D starting at w4 . There exists a set S such that the following holds: Ži.
S : tL l X l V Ž Ct ..
Žii.
S « V Ž Ct . y Sy.
Žiii. W : Sy. Živ. for e¨ ery u g V Ž D . y Ž V Ž F . j tL ., either S « u or D y V Ž R . has no Ž Ct , u.-path.
134
ANDERS YEO
Žv. If there is a cycle C in D co¨ ering X, then there is a F-canonical cycle, CX , in D, co¨ ering X, such that < V Ž CX . l Y < G < V Ž C . l Y <. Proof of Ži. ᎐ Živ.. Define the sets U s u g V Ž D . y V Ž R . y tL : tL l V Ž R . « u4 Z s z g V Ž D . y V Ž R .: Ž tL l V Ž R ..q£ z 4 T X s ¨ g V Ž Ct .: ᭚q g V Ž D . y V Ž F . y tL such that Ž tL l R . « q ª ¨4 T s T X j ¨ g V Ž Ct .: ¨ f tL l X 4 For every w g W we define S0w s ⭋, S1w s wq4 , and Siw s r g V Ž Ct .: w ᭚q g Siy1 such that ryª q4 for i s 2, 3, . . . , < V Ž Ct .<. Observe that there exists n w Ž w g W ., such that S0w ; S1w ; S2w ; ⭈⭈⭈ ; S nww s S nww q1 s ⭈⭈⭈ s S
ALGORITHMS FINDING CYCLES
135
Observe that F Y is a 1-path-cycle subgraph in D y V Ž R . which covers X and whose path P X starts in U and terminates in Z. If Y s X then clearly < V Ž F Y . l Y < s < V Ž Ct . l Y <. If Y / X then Y s V Ž D ., D is a SBD, and d G 3, since V c Ž q1 . s V c Ž q d ., by Definition 4.2Ži. and the fact that D is a SBD. Now note that < V Ž F Y . l Y < G < V Ž Ct . l Y <, as q dy 1 g V Ž F Y . y V Ž Ct . and V Ž Ct . y V Ž F Y . : p14 . Define i g 1, 2, . . . , t y 14 such that q d g Ci . By the definition of U and Z, we observe that F Y j Ciq1 j Ciq2 j ⭈⭈⭈ j Cty1 is a contradiction against Definition 4.2Žii.. This shows that T l S s ⭋. Since S l T s ⭋ we get S : tL l X l V Ž Ct ., which proves Ži.. From the definition of S we get that S « V Ž Ct . y Sy and W : Sy, which proves Žii. and Žiii.. To prove Živ. let u g V Ž D . y V Ž F . y tL such that S £ u. Let s g S be arbitrary with u ª s. We must have Ž tL l R . £ u, since otherwise s g T which is a contradiction. Let q g Ž tL l R . be arbitrary such that u ª q. If there is a Ž Ct , u.-path, P, in D y V Ž R ., then Pq is a Ž Ct , R .-path, with qyf tL which is a contradiction against Theorem 4.3. Therefore, if S £ u then there is no Ž Ct , u.-path in D y V Ž R .. This proves Živ.. Proof of Žv.. Let tL be defined as in Theorem 4.3. Let S be defined as above and let C be a cycle covering X. Let C² V Ž D . y V Ž R .: s P1 j P2 j ⭈⭈⭈ j Pf , where P1 , . . . , Pf are pairwise vertex disjoint paths. We may without loss of generality assume that there exists an integer, l, such that V Ž Pi . l V Ž Ct . / ⭋ for 1 F i F l and V Ž Pi . l V Ž Ct . s ⭋ for l q 1 F i F f. Let ¨ i be the last vertex from Ct on the path Pi Ž i s 1, 2, . . . , l ., and let u i be the first vertex from Ct on the path Pi Ž i s 1, 2, . . . , l .. Finally, let ri be the predecessor of u i in C. We will now show the following four statements: Ž ␣ . If s g S l V Ž Pi w u i , ¨ i x. y u i 4., then the predecessor of s on Pi lies in Sy. Let sX be the predecessor of s on Pi . By Živ. we obtain that sX g V Ž Ct ., and by Žii. we obtain that sX g Sy. Ž  . ¨ i g Sy and u i g S Žfor i s 1, 2, . . . , l .. Let yi be the successor of the last vertex in Pi , on C. Note that C w ¨ i , yi x is a Ž Ct , R .-path, which implies that ¨ i g W : Sy Žby the definition of W and by Žiii... This shows the first part. By Ži., we obtain that S : X, which implies that S : V Ž C .. Since ¨ i g Sy Žfor i s 1, 2, . . . , l . and < S < s < Sy< , there are l vertices from S whose predecessor on C is not from Sy. By Ž ␣ . they must be u1 , u 2 , . . . , u l 4 , which shows the second part. Ž␥ .
136
ANDERS YEO
the digraph obtained from the l paths P1 , P2 , . . . , Pl , where we have deleted all arcs from Sy to S. By Ž ␣ . and Ž  ., DX consists of < S < Ž S, Sy. -paths. When we add the arcs between vertices in Sy and their successors in Ct , we obtain a cycle subgraph F Y , in D. We observe that the cycle subgraph F U s C1 j C2 j ⭈⭈⭈ j Cty1 j F Y , has X : V Ž F U . and l < V Ž F U .< s < V Ž F .< y < V Ž Ct .< q
6. MAIN ALGORITHM The following theorem is the main result of this paper. THEOREM 6.1. Let D be a SMD and let X : Y : V Ž D ., such that either Y s X or D is a SBD and Y s V Ž D .. We can in O Ž< V Ž D .< 5 . time find a cycle co¨ ering X in D Ž if it exists. and which includes the maximum number of ¨ ertices from Y of all such cycles. Proof. If F s C1 j C2 j ⭈⭈⭈ j Ct is a Ž X, Y .-singular subgraph, with t G 2, in D, then we define a new SMD, DX s Ž V X , AX . as follows: Let U s tL Žusing Theorem 4.3. and define R s C1 j C2 j ⭈⭈⭈ j Cty1 W s w g V Ž Ct .: ᭚Ž Ct , R .-path in D, starting at w4 Z s Wq, on the cycle Ct B s b: b g V Ž D . y V Ž F . y U and Z « b4 E s V Ž D . y V Ž Ct . y B. We are only going to need DX when Z / ⭋, so assume that this is the case. Let zU g Z and let the vertex set of DX be V X s W j Z j E.
ALGORITHMS FINDING CYCLES
137
Furthermore, let the arc set of DX be AX s A Ž D ²W j E : . j xz : x g E y U and z g Z 4 j wz : w g W and z g Z y zU 4 j zw: z g Z and w g W 4 . Let X X s X l ŽW j Z j E . and let Y X s Y l ŽW j Z j E .. Let S be defined as in Lemma 5.2 and observe that Z : S : X l U . By Theorem 4.3 and Lemma 5.2Živ., we observe that in D Žas well as in DX . we have E « Z. Let F X s C1X j C2X j ⭈⭈⭈ j CtXX be a Ž X X , Y X .-singular subgraph in DX Žif it exists.. We will now show the following claims: Ža. Given a cycle, CX , in DX , with X X : V Ž CX ., we can find a cycle C in D, with X : V Ž C . and < V Ž CX .< q < V Ž Ct .< y < Z < y < W < s < V Ž C .<. Clearly Z : V Ž CX ., since Z : X X , and Zqs W on CX , since E « Z : U in DX . Now observe that the predecessor of zU on CX must come from E, and that CX² V Ž CX . y E : is a collection of vertex disjoint Ž Z, W .-paths, P1 , P2 , . . . , Pm Ž m G 1.. For i s 1, 2, . . . , m let the path Pi terminate in vertex wi . Without loss of generality assume that for all i s 1, 2, . . . , m, Ct w wi , wiq1 x contains no vertices from the set w 1 , . . . , wm 4 y wi , wiq1 4 Žwhere wmq 1 s w 1 by definition.. For all i s 1, 2, . . . , m we replace the x Ž path Pi with the path Ct w wq iy1 , wi , to obtain a cycle C in D where w 0 s wm by definition.. We observe that < V Ž C .< s < V Ž CX .< q < V Ž Ct .< y m
138
ANDERS YEO
Žc. Z j W ; V Ž CtXX .. Assume that there are distinct vertices, zX and z , in Z, such that zX g V Ž CiX . and zY g V Ž CXj . with i / j. Assume w.l.o.g. that i - j, and observe that zY ª Ž zX .q, as Ž zX .qg W. This is, however, a contradiction against Theorem 4.3, as V c Ž zX . s V c Ž zY . / V c ŽŽ zY .q. . As Zqs W there is a cycle CiX in F X , such that Z j W : V Ž CiX .. Assume that i / tX , and let z g Z be arbitrary. Let q g V Ž CtXX . y V c Ž z ., and observe that q ª z which, by Theorem 4.3, implies that V c Ž qq. s V c Ž zy. . This implies that V c Ž qq. s V c Ž zy. / V c Ž z . and V c Ž qqq . / V c Ž qq. s V c Ž zy. , which is a contradiction against Theorem 4.3, as qqª z. Therefore, Z j W : V Ž CtXX .. However, since Ž zU .yf Z j W, we obtain the desired result. Y
A short scheme of the O Ž< V Ž D .< 5 . algorithm follows: Use Theorem 4.4 to obtain a Ž X, Y .-singular subgraph in D, if it exists. If it does not exist, then there is no cycle covering X. We then transform D, into DX as illustrated above. If Z s ⭋ then there is no cycle covering X; otherwise use Theorem 4.4 to obtain a Ž X X , Y X .-singular subgraph in DX , if it exists. We continue this process until we either obtain a cycle, or we prove that there is no cycle covering X. The correctness of the algorithm is seen from Ža. and Žb.. By Žc. we observe that the set E, which is used in the transformation, decreases in size for every iteration. This implies that we use Theorem 4.4 O Ž< V Ž D .<. times, which together with the O Ž< V Ž D .< 4 . time bound in Theorem 4.4 gives us the desired result.
7. OPEN PROBLEMS AND CONJECTURES We now state some of the interesting open problems in the area of this paper. The unsolved conjectures from w4x are the following. CONJECTURE 7.1 w4x. If D is a SMD, then there are polynomial time algorithms for the following problems: Ž1. Construct a longest cycle in D. Ž2. Gi¨ en set X : V Ž D ., find a cycle containing the maximum number of ¨ ertices from X. Part Ž1. of the above conjecture is true for SBD Žcf. w13x.. However, part Ž2. is still unsolved for SBD’s, as well as for SMD’s. We now state the following conjecture. CONJECTURE 7.2. If D is a SMD and X : V Ž D ., then there is a polynomial time algorithm for finding a cycle co¨ ering X Ž if it exists. and which is the longest of all such cycles.
ALGORITHMS FINDING CYCLES
139
We have shown that if D is a SBD and X : V Ž D ., then there is a polynomial time algorithm for finding a cycle covering X Žif it exists. and which is the longest of all such cycles. This result gives support for the above conjecture. Finally we conclude this section with a conjecture which, if true, would imply all the other conjectures mentioned in this section. CONJECTURE 7.3. If D is a SMD and X : Y : V Ž D ., then there is a polynomial time algorithm for finding a cycle co¨ ering X Ž if it exists. and which includes the maximum number of ¨ ertices from Y of all such cycles. REFERENCES 1. J. Bang-Jensen and G. Gutin, Vertex heaviest paths and cycles in quasi-transitive digraphs, Discrete Math. 163 Ž1996., 217᎐223. 2. J. Bang-Jensen, G. Gutin, and J. Huang, A sufficient condition for a semicomplete multipartite digraph to be Hamiltonian, Discrete Math. 161 Ž1996., 1᎐12. 3. J. Bang-Jensen, G. Gutin, and A. Yeo, Hamiltonian cycles avoiding prescribed arcs in tournaments, Combin. Probab. Comput. 6 Ž1997., 255᎐261. 4. J. Bang-Jensen, G. Gutin, and A. Yeo, A polynomial algorithm for the Hamiltonian cycle problem in semicomplete multipartite digraphs, J. Graph Theory 29 Ž1998., 111᎐132. 5. J. Bang-Jensen and Y. Manoussakis, Cycles through k vertices and k arcs in bipartite tournaments, Combinatorica 14 Ž1994., 243᎐246. 6. J. Bang-Jensen and Y. Manoussakis, Weakly Hamiltonian-connected vertices in bipartite tournaments, J. Combin. Theory. Ser. B 63 Ž1995., 261᎐280. 7. J. Bang-Jensen and C. Thomassen, A polynomial algorithm for the 2-path problem for semicomplete digraphs, SIAM J. Discrete Math. 5 Ž1992., 366᎐376. 8. J. A. Bondy and U. S. R. Murty, ‘‘Graph Theory with Applications,’’ North-Holland, Amsterdam, 1976. 9. P. Camion, Chemins et circuits hamiltoniens des graphes complets, C. R. Acad. Sci. Paris 249 Ž1959., 2151᎐2152. 10. G. Gutin, A criterion for complete bipartite digraphs to be Hamiltonian, Vestsı Acad. Na¨ uk BSSR Ser. Fiz.-Mat. Na¨ uk 1 Ž1984., 99᎐100. wRussianx 11. G. Gutin, Cycles and paths in semicomplete multipartite digraphs, theorems and algorithms: a survey, J. Graph Theory 19 Ž1995., 481᎐505. 12. G. Gutin, Finding the largest contour in a complete bipartite digraph, Kibernetika 2 Ž1987., 117᎐118. wRussianx 13. G. Gutin, ‘‘Paths and Cycles in Digraphs,’’ Ph.D. thesis, Tel Aviv Univ., 1993. 14. R. Haggkvist and Y. Manoussakis, Cycles and paths in bipartite tournaments with ¨ spanning configurations, Combinatorica 9 Ž1989., 33᎐38. 15. Y. Manoussakis, A linear time algorithm for finding Hamiltonian cycle in tournaments, Discrete Appl. Math. 36 Ž1992., 199᎐202. 16. Y. Manoussakis and Z. Tuza, Polynomial algorithms for finding cycles and paths in bipartite tournaments, SIAM J. Discrete Math. 3 Ž1990., 537᎐543. 17. K. G. Murty, ‘‘Network Programming,’’ Prentice᎐Hall, Englewood Cliffs, NJ, 1992. 18. A. Yeo, One-diregular subgraphs in semicomplete multipartite digraphs, J. Graph Theory 24, No. 11 Ž1997., 1᎐11. 19. C. Q. Zhang, Hamiltonian paths in multipartite oriented graphs, Ann. Discrete Math. 41 Ž1989., 499᎐514.