The Complexity of Routing Problems in Forbidden-Transition Graphs and Edge-Colored Graphs

The notion of forbidden-transition graphs allows for a robust generalization of walks in graphs. In a forbidden-transition graph, every pair of edges incident to a common vertex is permitted or forbidden; a walk is compatible if all pairs of consecutive edges on the walk are permitted. Forbidden-transition graphs and related models have found applications in a variety of fields, such as routing in optical telecommunication networks, road networks, and bio-informatics. A widely-studied special case are edge-colored graphs, where a compatible walk is forbidden to take two edges of the same color in a row. We initiate the study of fundamental problems on finding paths, cycles and walks in forbidden-transition graphs from the point of view of parameterized complexity, including an in-depth study of tractability with regards to various graph-width parameters. Among several results, we prove that finding a simple compatible path between given endpoints in a forbidden-transition graph is W[1]-hard when parameterized by the vertex-deletion distance to a linear forest (so it is also hard when parameterized by pathwidth or treewidth). On the other hand, we show an algebraic trick that yields tractability when parameterized by treewidth for finding a compatible Hamiltonian cycle in the edge-colored graph setting.

when parameterized by the vertex-deletion distance to a linear forest (so it is also

Introduction
Graphs have proved to be an extremely useful tool to model routing problems in a very wide range of applications. However, we sometimes need to express constraints on the permitted walks that are stronger than what the standard graph model allows for. For example, in a road network, there can be a crossroad where drivers are not allowed to turn right. In this case, many walks in the underlying graph without transition restrictions would correspond to routes that a driver is not allowed to use. To overcome this limitation, Kotzig introduced forbidden-transition graphs [39]. Let G be an undirected graph. A transition in G is an unordered pair of adjacent edges. Every time a walk in G uses two edges uv and vw consecutively, we say that the walk uses the transition {uv, vw}. A transition system of G is a set of transitions in G. A forbidden-transition graph is a tuple (G, T ) of a graph G together with a transition system T of G. 1 We say that a transition is permitted if it is in T and it is forbidden otherwise. We say a walk is compatible with T , or T -compatible, if all the transitions it uses are permitted, that is, they are in T . We omit reference to T when it is clear from the context. For notational clarity, it is sometimes useful to refer to the transitions T (v) of a specific vertex v ∈ V (G), that is, Since their introduction, forbidden-transition graphs and related models have found applications in a variety of fields, such as routing in optical telecommunication networks [2], road networks [6], and bio-informatics [16]. Problems of routing, connectivity, and robustness in those graphs have received a lot of attention but unfortunately, those problems generally turn out to be algorithmically very difficult, even on very restricted subclasses of graphs. In [49], Szeider famously proved that even determining the existence of a compatible (elementary) path between two given vertices of a forbidden-transition graph is NP-complete. Similarly, many known results about forbidden-transition graphs are proofs of NP-completeness of problems that are polynomially solvable on standard graphs (e.g. [1], [7], [18], [27], [28], [34], [35], [49]).
A very interesting specific case of compatible walks in forbidden-transition graphs are properly colored walks in edge-colored graphs. Here, a graph is given together with a coloring of its edges and we say that a walk is properly colored if it does not use consecutively two edges of the same color. These graphs have been introduced by Dorninger in [16] to study chromosome arrangements. The problem of properly colored Hamiltonian cycles was the first problem explicitly studied on edge-colored graphs and this problem and its variants (such as longest elementary cycle or spanning trails among many others) are especially well studied in the literature. We refer the reader to [30] or [5] for surveys on these problems and to [4], [13], [14], [31], [40] or [41] for recent developments.
We remark that edge-colored graphs with two colors generalize directed graphs in the following sense. Assume that the colors are red and blue, take a directed graph G, and replace every arc e = (u, v) ∈ E(G) with a new vertex x e , a blue edge ux e and a red edge vx e . One can observe that each properly colored walk in the resulting graph corresponds to a walk in G that respects arc directions (but may go backwards). Using this observation, for most of the problems asking for paths, cycles, and walks, it is easy to provide a reduction from the directed graph setting to an edge-colored setting with two colors.
Because of their expressiveness and wide range of applications, the study of forbidden-transition graphs is a fast-emerging field and has been the subject of growing attention in the past decades but we are still very far from understanding them as well as regular graphs. Our aim in this paper is to study the parameterized complexity of some known NP-complete problems concerning existence of paths, cycles, or walks (which is the natural class of problems in this context), in general forbidden-transition graphs as well as in the specific case of edge-colored graphs. We specifically focus on some problems of great practical interest, such as the existence of an elementary path or the length of a shortest path between given vertices, the problem of Hamiltonian cycles, or linkage problems where we try to connect pairs of vertices by vertex-or edgedisjoint paths. A very rich toolbox already exists to study fixed-parameter tractability in standard graphs (see [15] for example) but the generalization of these concepts to forbidden-transition graphs is widely unexplored and raises many challenges that we hope to see get more attention in the future.

Our Results
In Sect. 3, we study the problem of shortest compatible paths between two vertices s and t in a forbidden-transition graph. Recall that determining whether there exists a compatible path between s and t is known to be NP-complete [49]. A simple application of the color-coding technique shows that this problem is fixed-parameter tractable when parameterized by the length of the path. We improve upon this observation by showing that the complexity of finding a shortest compatible path from s to t is actually fixed-parameter tractable when parameterized by the length of the detour that the forbidden transitions impose. In other words, determining whether there exists a compatible path of length at most d(s, t) + k where d(s, t) is the length of the shortest path between s and t in the underlying graph with no forbidden transitions, is fixedparameter tractable when parameterized by k. Our algorithm follows the main ideas of the algorithm for the Exact Detour problem by Bezáková et al. [10].
In Sect. 4, we turn our attention to graph-width parameters. The rich ecosystem of relevant graph-width parameters is depicted in Fig. 1; see [24,44,51] for the corresponding boundedness and unboundedness relations on treecut-width. Fig. 1 A hierarchy of graph-width parameters considered in this work. An arrow from a to b represents the fact that a bound on parameter b imposes a bound on parameter a, but there exist families of graphs with bounded a and unbounded b. A parameter a is green and dashed if detecting a compatible s-t path is fixed-parameter tractable with respect to a; the parameter is red and solid if this problem is W[1]-hard (Color figure online) First, we focus on the NP-complete problem of determining whether there exists a compatible path between s and t in a forbidden-transition graph. Since the problem is fixed-parameter tractable when parameterized by the length of the path (see Sect. 3), it is also fixed-parameter tractable when parameterized by the vertex cover number or the treedepth of the graph, as bounding the vertex cover number or the treedepth of the graph by k bounds the length of the longest simple path by 2k or 2 k − 1, respectively. Our main result is a negative one: the problem becomes W [1]-hard if one makes one step further to the parameter modulator to a linear forest, i.e., the number of vertices one has to remove from the graph to turn it into a union of vertex-disjoint paths. A small tweak of the reduction shows that finding a Hamiltonian cycle is W [1]-hard with respect to the size of a modulator to treewidth 2. Our reduction in particular implies hardness for the parameters pathwidth and treewidth (for both the compatible path and Hamiltonian cycle problems). The reduction is technically involved and is the main negative result in this paper.
On the other hand, we show that if one considers parameters based on edge cuts (as opposed to vertex cuts, like in treewidth), one can obtain nontrivial tractability results. Treecut-width is a width notion based on edge cuts, introduced by Wollan [51], and playing the role of treewidth in the world of the immersion relation. We prove that the problem of finding a compatible s-t path is fixed-parameter tractable when parameterized by the treecut-width of the graph. More precisely, the problem can be solved in time k O (k 2 ) · n 3 where k denotes the treecut-width.
In the light of the hardness in general forbidden-transition graphs of detecting s-t paths, the most fundamental connectivity problem, we move to the special case of properly colored paths in edge-colored graphs. As finding a (simple) properly colored path between given endpoints in an edge-colored graph is polynomial-time solvable, we focus on the problem of finding a Hamiltonian cycle. We introduce a novel algebraic trick that shows that in edge-colored graphs, finding a properly colored Hamiltonian cycle is fixed-parameter tractable when parameterized by the treewidth of the graph. More specifically, the problem can be solved in time 2 O(k) · (|V (G)| + |V (T )| + ) where k is the treewidth, T is the tree of the decomposition and is the number of different colors the edges can have. The crucial property of the result is that , the number of colors, is not required to be bounded in the parameter and does not appear in the exponential part of the running-time bound (an exponential dependency on both k and is not hard to achieve).
After discussing graph-width notions, in Sect. 5, we move to the Disjoint Paths problem. In this problem, we are given a directed graph and a sequence (s 1 , t 1 ), (s 2 , t 2 ), . . . , (s r , t r ) of terminal pairs; the goal is to find compatible paths P 1 , P 2 , . . . , P r such that P i starts in s i and ends in t i and the paths P i are pairwise edge-or vertex-disjoint. In the undirected graph setting, the fixed-parameter tractability (parameterized by the number of requests r ) of this problem is a milestone result in the Graph Minors series of Robertson and Seymour [48].
Observe that beyond undirected graphs the problem quickly becomes hard. As discussed, the setting of properly colored paths in edge-colored graphs generalizes directed graphs, and the Disjoint Paths problem for r = 2 is NP-hard in directed graphs [23]. Furthermore, in general graphs with transitions the case r = 1 is NP-hard. Hence, we focus on the specific case where the path P i is required to be a shortest s i -t i path, even in the unrestricted graph. In directed graphs, a tractability result for this problem has been obtained by Bérczi and Kobayashi [9] for r = 2. This problem is currently a very active topic and new algorithms have been found very recently for several variants in the case r = 2. Polynomial algorithms have been developed by Gottschau et al. [26] and by Kobayashi and Sako [37] for undirected graphs with non-negative weighted edges and by Bang-Jensen et al. [3] in the directed unweighted case where paths do not have to be shortest but have bounded lengths. At the point of writing, the complexity of the problem was still open for r ≥ 3. In the meantime, it was shown that finding r disjoint shortest paths in undirected, unweighted graphs is indeed polynomial-time solvable for each fixed r [8,42].
In the light of the status described above, in this work we focus on the case r = 2 in directed forbidden-transition graphs. Extending the results of Bérczi and Kobayashi [9], we show that the problem remains polynomial-time solvable both in the edge-and vertex-disjoint case. The arguments are presented in Sect. 5.

Preliminaries
For each n ∈ N we use [n] to denote {1, 2, . . . , n}. Unless stated otherwise, all graphs are undirected, without self-loops and parallel edges.

Graphs
Let G be an undirected graph. By V (G) and E(G) we denote the vertex and edge set of G, respectively. For where v i s are vertices of G, e i s are edges of G, and for every 1 ≤ i ≤ , the vertices v i and v i+1 are the two endpoints of the edge e i . A walk is closed if its first vertex is also its last vertex. The length of a walk W equals , the number of edges in W . A path is a walk in which no vertex occurs twice, a cycle is a closed walk in which no vertex occurs twice except the first and last vertex. Usually we will denote paths and cycles simply by their sequence of vertices. By dist G (s, t) we mean the length of a simple s-t path in G (ignoring any transitions).
For a graph G, a tree decomposition of G is a pair (T , β) where T is a tree and β : V (T ) → 2 V (G) such that the following holds: (i) for every v ∈ V (G), the set {t ∈ V (T ) | v ∈ β(t)} induces a nonempty connected subtree of T , and (ii) for every uv ∈ E(G), there exists t ∈ V (T ) with u, v ∈ β(t). That is, the function β assigns to every node t ∈ V (T ) a subset β(t) ⊆ V (G), often called a bag. It is often convenient to root T at an arbitrary vertex. The width of a tree decomposition (T , β) equals max t∈V (T ) |β(t)| − 1, and the treewidth of a graph is the minimum possible width of its tree decomposition.

Parameterized Complexity
A parameterized problem is a set of instances of the form (x, k), where x ∈ * for a finite alphabet set , and k ∈ N is the parameter. A parameterized problem Q is fixed-parameter tractable and in the class FPT, if there exists an algorithm that on (1) , where f is a computable function independent of n = |x|; an algorithm with this running time is called fixed-parameter algorithm. A parameterized reduction from a parameterized problem L ⊆ * × N with parameter k to a parameterized problem where f is a computable function independent of n = |x|. For more discussion on parameterized complexity, we refer to the literature [15,17,22,46].

Detours
As Szeider [49] proved, it is NP-hard to determine whether a given forbidden-transition graph (G, T ) contains a compatible s-t path for two given vertices s and t. This of course implies that it is NP-hard to check whether there is a compatible s-t path of at most some given length. In contrast, it is polynomial-time solvable to decide whether there is a compatible s-t path which has length at most dist G (s, t). This can for example be seen by using the following strategy. Construct the line graph H of G. (That is, H has vertex set E(G) and two vertices in H are adjacent if the corresponding edges in G share an endpoint.) For each vertex v ∈ V (G) and each pair e, f of edges incident to v such that e and f are not compatible, remove the edge e f from H . Introduce two new vertices s and t into H and make them adjacent to every vertex corresponding to an edge incident in G with s or t, respectively. Finally, check whether H contains an (ordinary) s -t path of length at most dist G (s, t) + 1. However, we note that the above method does not combine well with graph width parameters considered in this work (recall Fig. 1); if G is a star on n + 1 vertices, both, its vertex cover and treecut-width are equal to one, while line graph H of G contains a clique of size n.
In this section we improve on the above observation by showing that checking for compatible s-t paths which are marginally longer than dist G (s, t) can also be done efficiently. That is we are going to show the fixed-parameter tractability of the following problem.
For notational convenience, we slightly generalize the notion of an x-y path as follows. For a given graph G and x, y We first show fixed-parameter tractability of the ComPath problem, which will be later used as a black box in our algorithm for ComDetour. The algorithm for ComPath uses a standard color-coding approach (see [15]), slightly modified to track the transitions.

ComPath
Parameter: k ∈ N Input: An instance (G, T , x, y, k) where (G, T ) is a forbidden-transition graph, x, y ∈ V (G) ∪ E(G), and k ∈ N. Task: Decide whether there exists a T -compatible x-y path in G of length at most k. If so, return the length of a shortest such path.
The algorithm can be presented using random colorings but this would complicate the analysis later. We instead use the notion of perfect hash families. Let n, k ∈ N and let U be a set of size n. A k-perfect hash family of U is a family F of functions from U to [k] such that for each subset S ⊆ U of size at most k there exists a function f ∈ F such that f (S) = [k] (that is, f is injective on S). Naor, Schulman, and Srinivasan [45] showed that a k-perfect hash family of size e k k O(log k) log n can be computed in e k k O(log k) n log n time; see also [15,Section 5.6.1].

Theorem 3.1 There exists an algorithm solving ComPath on n-vertex graphs in time
Proof Let (G, T , x, y, k) be the input instance. First, consider the case where x, y ∈ V (G). The algorithm works as follows. We start by coloring the vertices in G using a family of perfect hash functions. Compute a (k − 1)-perfect hash family F of V (G) in e k k O(log k) n log n time. Iterate over all elements f ∈ F and for each such element f proceed as follows. Generate a coloring of V (G) by starting with coloring x and y with two unique colors, say 1 and k + 1 and then coloring the rest of vertices of G with colors 2, . . . , k, according to the values assigned by f . That is, put the color of a vertex v ∈ V (G) \ {x, y} to be f (v) + 1. Let c : V (G) → [k + 1] be the resulting coloring and for each i ∈ [k + 1] denote by C i the set c −1 (i). Observe that it suffices to prove the following claim.
Claim Let x, y ∈ V (G). There exists an algorithm to test whether there exists a colorful T -compatible x-y path with at most k + 1 vertices in time 2 k n O (1) .
Proof (of Claim) We use the following dynamic programming approach that computes a Observe that this is a correct way of computing the entries D [S, u, v]. As to the running time, the number of possible sets S is bounded by 2 k (as 1 is always included in S  (1) . Analogously, if we search for a colorful T -compatible x-y path when {x, y} ∩ E(G) = ∅, we give unique colors to the second and/or last but one vertex of a potential path and slightly modify computation of the table D and we look for an optimal solution in S that respects the corresponding conditions.
We are ready to prove the fixed-parameter tractability of ComDetour. Our algorithm for ComDetour is based on the work of Bezáková et al. [10] that shows that computing s-t paths of length exactly dist(s, t) + k in ordinary graphs is fixedparameter tractable with respect to k. The basic idea is that in such a path there are at most k segments in which no "progress" is made towards reaching t. These k segments can be determined locally by applying the algorithm for ComPath from above. The remaining parts can be computed by ordinary dynamic programming as for computing shortest paths.

Theorem 3.2 There exists an algorithm solving ComDetour in n-vertex graphs in
Proof Let (G, T , s, t, k) be the input instance of ComDetour and let d = dist G (s, t). We can clearly assume that d > k, as otherwise we can compute whether (G, T , s, t, k) is a yes-instance using the algorithm for ComPath with parameter d + k ≤ 2k. For Clearly {s} = X 0 and t ∈ X d . Note that each compatible s-t-path of length at most d + k must be contained in the graph induced by X = i∈{0,1,...,d+k} X i , therefore we can safely assume that X = V (G). For two distinct layers X i , X j , we say that X i is higher (resp. lower) than X j if i > j (resp i < j). We use the following notation: The algorithm uses a dynamic-programming procedure that computes a table D. Table D is indexed by the inter-layer edges of G. For every inter-layer edge x y ∈ E(G) such that y belongs to a higher layer than x, the entry D[x y] contains the length of a shortest compatible x y-t path in G (x,∞) if it exists and if dist(s, x) + ≤ d + k; otherwise D[x y] = ∞. Note that it suffices to compute the entries of the table D because we can then look up whether there is a solution in the entries corresponding to the edges incident with s (which are all inter-layer edges). We first compute the entries for edges with the highest layers and then for edges in successively lower layers. Intuitively, when filling D for a specific inter-layer edge uv, we can rely on the fact that each solution path using uv will contain an inter-layer edge wx in a higher layer and it will reach wx from uv in at most 2k steps. Thus, when filling the table for uv, we may refer to the correct entry for wx and compute the path between uv and wx using a call to the algorithm for ComPath.
At the beginning of the procedure we initialize the table, putting D[x y] = ∞ for every inter-layer edge x y ∈ E(G). Next, we compute entries of D for the last 2k + 1 layers: for every inter-layer edge Observe that this will fill D[x y] with the correct value according to the definition of D.
Then, we inductively fill in earlier layers by carrying out the following computation steps: (1) For every integer m from d − k − 1 down to 0 and for every pair of vertices x, u such that dist G (s, x) = m and m < dist G (s, u) ≤ m + k + 1 we do the following: (a) For every pair of edges e, f ∈ E(G (x,u] ) such that e = x y (so e is an inter-layer edge) and f = vu for some vertices y, v ∈ V (G (x,u] ), we do the following: (i) We solve the ComPath instance (G (x,u] , T , e, f , 2k).
(ii) If the answer is negative, we continue with the next pair of candidates for e and f . We now show the correctness of the algorithm. Observe first, that each table entry D[e] only receives a non-infinity value if there is a compatible e-t path of length at most d + k; this is ensured by the way the entries are filled in step (iv). Moreover, each non-infinity entry D[e] contains the length of some compatible e-t path. Thus, the algorithm accepts only if there is a compatible s-t path of length at most d + k. In particular, if there exists no such path, then the answer is correct. Moreover, if there exists a compatible s-t path in G of length ≤ d + k, then ν ≥ . Now assume that there exists a compatible s-t path in G of length such that ≤ d + k. It remains to show that ν ≤ . We prove the stronger statement that for each inter-layer edge x y we have that D[x y] is at most the length, , of a shortest compatible x y-t path in G (x,∞) that satisfies dist G (s, x) + ≤ d + k or ∞ if no such path exists. The proof is by induction on d − m where m is the layer of x. By the above, the statement holds for m ≥ d − k. Now assume that m < d − k. If there is no suitable compatible x y-t path, the statement clearly holds. Otherwise, let P be such a path. We claim that it suffices to show that on P there exist consecutive vertices v, u, z such that the following properties hold. [u, t] be the subpath of P from u to t. Then P[u, t] is contained in G (u,∞) . (P4) There are at most 2k edges on P between (incl.) x y and vu.
Let e = x y, f = vu, and g = uz. If the above claim is true, then in Step (1) above we will guess x and u by (P1); in Step (a) we will guess e and f by definition of e; we will find an e-f path at most as long as the corresponding subpath of P in Step (i) by (P4); and we will consider D[g] in the minimum in Step (iv) by (P2) and since P is compatible. Furthermore, D[g] is at most the length, u , of P[u, t]: By (P3), P[u, t] is a path in G (u,∞) . To see that it satisfies the condition on its length let = − u .
is at most the length of P [u, t]. Thus D[e] will receive a value that is at most the length of P in Step (iv), as required.
Before proving the claim, let us observe the following. Say that an inter-layer edge h is a back edge if P traverses the vertex in h that is in a larger layer before the other vertex in h. Observe that the length of P is d +a +2b where a is the number of withinlayer edges in P and b the number of back edges in P. Thus, we have a + b ≤ k. In particular, there are at most k layers in which P contains at least two vertices. We will use this fact below.
It remains to prove our claim above. Since there are at most k layers in which P contains at least two vertices, in the layers m + 1, m + 2, . . . , m + k + 1 there is at least one vertex, u, on P such that u is the only vertex of P in u's layer. We claim that u together with the vertex, v, that precedes u on P and the vertex, z, that succeeds u on P satisfy the properties in the claim. Clearly, (P1) is satisfied. Since u is the only vertex of P on u's layer, also (P2) is satisfied. For the same reason, (P3) is satisfied. Finally, suppose that (P4) does not hold, that is, there are more than 2k edges between x y and vu on P. Then the length, , of P is at least 2k Thus, the claim holds, meaning that ν ≤ and the algorithm is correct.

Graph-Width Parameters
In this section we give our results pertaining to graph-width measures. As outlined in the introduction, finding a compatible s-t path of length at most k is fixed-parameter tractable with respect to k (see Theorem 3.1). Because the length of a simple path is upper-bounded by functions of the smallest size of a vertex cover and of the treedepth, tractability for these two parameters also follows. It is thus interesting to prove analogous tractability results for smaller and thus stronger parameters such as the treewidth of the input graph. However, in Sect. 4.1 we give a limit to this avenue: We prove that detecting compatible s-t paths and related problems are W[1]-hard with respect to the size of modulators to constant treewidth. In particular, this implies W[1]-hardness with respect to the pathwidth and the treewidth. Thus the natural dynamic-programming approaches that give fixed-parameter tractability in the ordinary graph setting likely do not work when taking transitions into account. It is interesting to note the contrast to the dynamic-programming approach for computing short detours (Theorem 3.2). The latter worked because the interface of a dynamic-programming enty consists of two single vertices and their transitions, whereas in the treewidth and pathwidth cases we would have to consider for each vertex in a separator all possible (unbounded number of) transitions.
On the positive side, if we focus on decompositional parameters that are based on edge cuts, rather than vertex separators, we can obtain tractability: In Sect. 4.2 we show that detecting compatible s-t paths is fixed-parameter tractable with respect to the treecut-width. Furthermore, the more restricted case of edge-colored graphs allows for efficient algorithms, too: In Sect. 4.3 we give a fixed-parameter algorithm for detecting properly colored Hamiltonian cycles in edge-colored graphs when parameterized by the treewidth.

Modulator to Linear Forest
Let G be an undirected graph. A modulator to a linear forest of G is a vertex subset S ⊆ V (G) such that G − S is a disjoint union of paths. The distance k of G to a linear forest is the minimum size, k, of a modulator to a linear forest. Note that the distance to a linear forest upper bounds the size of a minimum feedback-vertex set and the treewidth and hence W[1]-hardness for these two parameters is implied by W[1]-hardness for k. A modulator to treewidth two of G is a vertex subset S ⊆ V (G) such that G − S has treewidth at most two. The distance of G to treewidth two is the minimum size of a modulator to treewidth two. Analogously, the distance to treewidth two upper bounds the treewidth and hence W[1]-hardness for treewidth is implied by W[1]-hardness for the distance to treewidth two.
In this section, we first show that finding long paths or cycles is W[1]-hard with respect to the distance k to a linear forest. Moreover, assuming the Exponential Time Hypothesis (ETH), no f (k) · n o(k/ log k) -time algorithm can exist. Informally, the ETH states that 3-SAT on n-variable formulas cannot be solved in 2 o(n) time, see [32,33]. We obtain the following. Proof We first give a reduction to prove hardness of Item (i). We then modify the construction to obtain Item (ii).
Our reduction is from the Partitioned Subgraph Isomorphism (PSI) problem. Herein, we are given two graphs G and H , where V (H ) = [n H ] for some positive integer n H , and a vertex coloring col : V (G) → V (H ) of the vertices of G with colors that one-to-one correspond to the vertices of H . Moreover, each vertex of H is incident with at least one edge and for each edge {u, v} ∈ E(G) we have col(u) = col(v). We want to decide whether H is isomorphic to a subgraph of G while respecting the colors, that is, whether there is an injective mapping φ : Intuitively, our construction works as follows (see also Fig. 2 for an illustration): We first build a path from s to a vertex t 1 . This path is the concatenation of n H subpaths P 1 , . . . , P n H where each subpath is associated with a vertex of H . The subpath P i contains a vertex for each edge of G incident to a vertex colored i. We then use an extra vertex and an appropriate transition system so that one can choose any vertex v of G with color i and connect the endpoints of P i with a compatible path that skips exactly those vertices of P i that denote an edge adjacent to v. This comes down to choosing φ(i) = v. Finally, we connect t 1 to t by a sequence of gadgets each associated with an edge of H . Choosing a path through a gadget comes down to mapping an edge uv of H to an edge wx of G. Our transition system then requires the path in the gadget to visit the two vertices of P that denote the edge wx, which can only be done without repeating vertices if those vertices have been skipped between s and t 1 . This means that the endpoints of wx have to be the vertices we chose as φ(u) and φ(v). By ensuring that there is an edge between φ(u) and φ(v), we prove that φ is a subgraph isomorphism. We now continue with the formal description.
We construct a forbidden-transition graph (G , T ) as follows, see Fig. 2 for an illustration. We begin with G being empty. We will specify T by giving the permitted-transition sets Introduce new vertices s, t, t 1 into G . We construct the vertex-selection gadgets as follows.
Introduce a path P from s to t 1 into G ; we specify the number of vertices on P indirectly below. For each internal vertex v ∈ V (P) put T (v) = {{{u, v}, {v, w}}} where u and w are the neighbors of v in P. Additional edges and transitions for the vertices on P will be introduced below. Partition P into n H disjoint paths P 1 , . . . , P n H ; we specify the number of vertices in each of these paths in the next step.
For each i ∈ [n H ], proceed as follows. Let (e i a ) a∈[r i ] be an ordering of E i such that, for each v ∈ V i , the edges in E(v) form a segment in (e i a ) (observe that such an ordering exists since the endpoints of each edge in E(G) have two different colors).
Set the number of vertices in P i to r i + 4. For each a ∈ [r i ] denote the a + 2-th vertex on P i by x i a . We say that vertex x i a corresponds to the edge e i a of G. (We keep the first two and last two vertices of P i unnamed.) Next, introduce a vertex y i and for each vertex v ∈ V i proceed as follows. Let pre(v) be the vertex in P i that directly precedes on P i the first vertex corresponding to an edge in E G (v). Similarly, let post(v) be the vertex in P i that directly succeeds on P i the last vertex corresponding to an edge in E G (v). For later, it is useful to observe that all vertices on P i strictly between pre(v) and post(v) correspond to edges Moreover, add the following transitions: This finishes the construction of the vertex-selection gadgets, but further edges and transitions may be introduced later to the vertices of P.
We now construct the edge-verification gadgets. Let Furthermore, add the following transitions: . To conclude the construction of the edge-verification gadgets, add the following edges: Observe that Construction 4.1 can be carried out in polynomial time. We claim that the distance to linear forest of G is at most Moreover, no edges between two vertices on P have been introduced into G . Thus, Y ∪ Z is a modulator to a linear forest and G has distance at most 5m H to a linear forest. If Lemma 4.1 is correct, by the properties of PSI it thus follows that deciding whether a graph has a compatible s-t path is W[1]-hard with respect to the distance, k, to a linear forest, and that an f (k)n o(k/ log k) -time decision algorithm contradicts the ETH. We next show the correctness of Lemma 4.1.

Correctness. We now show that (G , T ) contains a compatible s-t path if and only if there is a subgraph isomorphism from H into G.
Suppose first that there is a subgraph isomorphism φ from H into G. Construct an s-t walk P by concatenating the following path segments (observe while reading the construction, that P is compatible): 1. The subpath on P from s to pre(φ(1)). 2. The three vertices pre(φ(1)), y 1 , post(φ(1)). 3. For each i = 2, 3, . . . , n H take: , Y , Z , and {t} and each vertex of Y and Z occurs only once in the definition of P , we have v ∈ V (P). Since each segment in the construction of P is a path, the two occurrences must be in different segments. Observe that all segments of P in steps 1 to 4 that are contained in V (P) are pairwise disjoint subpaths of P. Furthermore, all vertices in V (P) used in the segments constructed in step 5 are pairwise distinct. Thus, there is one occurrence of v in steps 1 to 4, and one in step 5. Moreover, v corresponds to some edge e of G. However, according to the steps 1 to 4, vertex v corresponds to some edge which is not incident to a vertex in φ(V (H )) and, according to step 5, vertex v corresponds to some edge which is incident to a vertex in φ(V (H )), a contradiction. Thus, indeed, P is a compatible s-t path, as required. Now suppose that (G , T ) contains a compatible s-t path P . Obviously, P starts with a subsegment of P. By construction of the transitions on vertices on P, at each internal vertex of P, the path P may either continue on P or go to some vertex of Y . Moreover, whenever P traverses a vertex of Y , it immediately returns to P with the next vertex. Path P hence begins with a segment which starts at s, alternatingly contains a sequence of vertices on P and a vertex of Y , and ends at t 1 where v is as defined above. For later, put P 1 to be the segment of P from s to t 1 and put P 2 to be the segment of P from t 1 to t. Observe that P 1 contains precisely all vertices of P except those that correspond to edges in G which are incident to the vertices of φ(Y ).
To show that φ is total and that φ is a subgraph isomorphism from H into G, we now argue that P 2  First, to see that φ is total, recall that each vertex i ∈ V (H ) is incident with at least one edge. Say i is incident with edge e p . Let x i a be the vertex that corresponds to an edge in G incident with a vertex of color i and that led to the definition of f p , that is, P 2 traverses x i a before or after z 2 p . Now recall that P 1 contains all vertices of P except those that correspond to the edges incident with vertices in φ(Y ). Since P 1 and P 2 are internally vertex-disjoint, i ∈ Y . It thus follows that φ is total.
To see that φ is a subgraph isomorphism, take any edge e p ∈ E(H ). Consider the edge f p and the two vertices x i a and x j b that led to the definition of f p , that is, x i a and x j b are traversed either before or after z 2 p . By the construction of the edges of z 2 p , we have e p = {i, j}. We again use the property that P 1 contains all vertices of P except those that correspond to the edges incident with vertices in φ(Y ). Since x i a and x j b are not in P 1 , they correspond to an edge incident with both φ(i) and φ( j), that is, f p = {φ(i), φ( j)}. Thus, indeed φ is a subgraph isomorphism, as required. This concludes the proof of Theorem 4.1 Item (i). The remaining parts are proved below.
Cycles. We now adapt Construction 4.1 to obtain Theorem 4.1 Item (ii). To this end, we simply add the edge {s, t} to G (and update the permitted transitions of s and t to allow for combining {s, t} with every other edge). Call the resulting graph G C . Observe that G C − (Y ∪ Z ) is a path with vertex set V (P) ∪ {t}, and hence G C has distance to a linear forest at most 5m H .
We claim that there is a compatible s-t path in G if and only if there is a compatible cycle in G C . The forward direction is trivial. For the backward direction, let C be a compatible cycle in G C . We show that C contains {s, t}. For a contradiction, assume it does not. Thus, C is a cycle in G . By the transitions of the vertices in P, cycle C does not contain an edge in P nor does it contain a vertex in Y . Let and observe that C is a cycle in G 1 . Observe that V (P) is an independent set in G 1 . Thus each cycle (not necessarily compatible) can be written as z for the corresponding values of p, i, a, and b. However, by the transitions of z p 2 , none of these cycles is compatible, a contradiction. Thus, C contains {s, t}. Hence, removing {s, t} from C gives an s-t path in G , concluding the proof.
We note that Theorem 4.1 immediately implies the following.

Corollary 4.1 Let (G, T ) be forbidden-transition graph and s, t two vertices in G. Let be a positive integer and let k be the distance of G to a linear forest. For each of the following, it is W[1]-hard with respect to k to decide and, moreover, an f (k) · n o(k/ log k) -time decision algorithm contradicts the ETH:
(i) whether G contains a compatible s-t path of length at least (or at most ), and (ii) whether G contains a compatible cycle of length at least (or at most ).
To put Corollary 4.1 in a wider context, note that, in contrast, deciding whether G contains an s-t path of length at least in ordinary graphs (without transitions) is fixed-parameter tractable with respect to treewidth (and, hence, also, parameterized by the distance to linear forest), see e.g., [15,Theorem 7.10].
We now adapt Construction 4.1 to prove that it is W[1]-hard with respect to the distance to treewidth two to check whether there is a compatible Hamiltonian cycle. This problem is, again, fixed-parameter tractable in ordinary graphs when parameterized by treewidth.

Theorem 4.2 Let G be a graph and k its distance to treewidth two. It is W[1]-hard with respect to k to decide whether G contains a compatible Hamiltonian cycle and, moreover, an f (k ) · n o(k / log k ) -time decision algorithm contradicts the ETH.
Proof To prove this theorem, we use Construction 4.1 and add a gadget that allows an s-t path in G to collect all so-far untraversed vertices, wherein we use transitions to not disturb the structure of G . The basic observation that we use is that the path P we have constructed in the correctness proof for detecting s-t paths above contains all vertices of G except segments of the path P. The idea now is to add a path Q which runs "parallel" to P (like a skewed ladder) and which starts after t and ends in s. Using transitions we allow the solution in each vertex v of Q to either continue to the next vertex of Q or to traverse the vertex parallel to v on P and then immediately return to the next vertex after v on Q. This allows the solution to traverse all vertices it missed on the traversal from s to t. Since Q is parallel to P, removing Y ∪ Z will result in a graph of treewidth two.
The formal construction is as follows. Construct a forbidden-transition graph Add a path Q consisting of n + 1 vertices to G 1 and identify the first and last vertex of Q with s and t, respectively. Let v 1 , v 2 , . . . , v n be the internal vertices of P and t = u 1 , u 2 , . . . , u n+1 = s the vertices of Q. For each i ∈ [n] proceed as follows. Add the edges {u i , v i }, and {v i , u i+1 }. Then, update the transition system T 1 by adding the This finishes the construction of G 1 and its transition system (as before, for all vertices with unspecified transition systems we allow all transitions).
. We claim thatG 1 has treewidth two. Observe that this graph consists only of the vertices in P and Q except for s and t. Now observe that, by the definition of the edges between P and Q, the following bags give a path decomposition forG 1 of width two. Note that we specify a bag containing t = u 1 for easier notation: Thus Y ∪ Z ∪{s, t} is a modulator of G 1 to treewidth two, meaning that G 1 has distance to treewidth two at most 5m H + 2, as required.
We claim that (G 1 , T 1 ) contains a compatible Hamiltonian cycle if and only if (G , T ) contains a compatible s-t path. Take a compatible s-t path P in (G , T ). Observe that in the correctness proof for detecting compatible s-t paths we have argued that P contains all vertices in Y and Z . In other words, the only vertices of G 1 that P does not contain are in P and Q. To obtain a compatible Hamiltonian cycle in (G 1 , T 1 ) from P , simply extend the path after arriving at t by following Q and visiting vertices in V (G 1 ) \ Q as needed in order to visit all vertices of G 1 .
In the other direction, by the updated transitions, a compatible Hamiltonian cycle in G 1 decomposes into two s-t paths, one path containing vertices of Q (and a subset of vertices in P), and another path contained in G , as claimed. This concludes the proof of W[1]-hardness of detecting compatible Hamiltonian cycles with respect to the distance to treewidth two and thus concludes the proof of Theorem 4.2.

Treecut-Width
In this section we are going to prove that the ComPath problem is fixed-parameter tractable with respect to treecut-width of G; the treecut-width is defined below. In the ComPath problem we get a forbidden-transition graph (G, T G ) and two vertices s, t ∈ V (G), and we want to decide whether there exists a compatible s-t path in G. The notion of treecut-width of a graph was introduced by Wollan [51]. In this section, to keep the notation succinct, we will sometimes refer to a forbidden-transition graph (G, T G ) simply as G and say that G has transition system T G .
Basic definitions and previous results. We now define treecut-width and the associated treecut decompositions, and we recap the relevant previous results on computing them. Consider a graph G (without transitions) and let v ∈ V (G) be a vertex of degree at most two. To suppress a vertex v ∈ V (G) means (i) to add an edge between v's two neighbors (possibly creating a parallel edge) and (ii) to delete v. For a partition A ∪ B of the vertex set of G such that both A and B are non-empty, we denote by E(A, B) the cut-set between A and B, i.e., the set we denote the set of edges incident with v (we omit the subscript if it is clear from the context). We define shrinking a (not necessarily connected) set Q ⊆ V (G) into q as an operation which replaces Q in G by a single new vertex q, and adds an edge qv for every edge uv ∈ E(G) such that u ∈ Q and v / ∈ Q. Note that this may create parallel edges.
A treecut decomposition of a graph G is a pair (T , X ) such that T is a rooted tree and X = {X t } t∈V (T ) is a partition of vertices of G in which we allow sets X t to be empty. For a node t, let T t be the subtree of T rooted in t. Let Y t := t ∈V (T t ) X t and Z t := V (G) \ Y t . For a non-root node t, let E t := E(Y t , Z t ), and for a root r , we set E r := ∅. We denote the vertices from Y t by y 1 , y 2 , y 3 , . . ., and the vertices from Z t by z 1 , z 2 , z 3 , . . .. Fig. 3 i A graph G and its tree-cut decomposition (T , X ) depicted in blue, with a distinguished node t. The left child of t is thin, while the right child is bold. ii The torso H t of (T , X ) at t, and iii the 3-center of H t (Color figure online) The torso of (T , X ) at a node t is a graph H t , constructed as follows. If T consists of a single node t, then the torso at t is G. Otherwise, let C 1 , . . . , C be the sets of the vertices of G corresponding to the connected components of T \ {t}. We construct the torso by shrinking C i into c i for each i ∈ [ ]. Note that a torso may have parallel edges. The 3-center H t of a torso H t is the graph obtained from H t by suppressing vertices of degree at most two which belong to the set The treecut-width of G is the minimum width of a treecut decomposition of G (see Fig. 3).

Theorem 4.3 (Kim et al. [36])
There exists an algorithm that, given a graph G and k ∈ N, either outputs a treecut decomposition of G of width at most 2k or correctly reports that G has treecut width larger than k in time 2 O(k 2 log k) · |V (G)| 2 .
A non-root node t of a treecut decomposition (T , X ) is thin if |E t | ≤ 2 and it is bold otherwise. Denote by A t and B t , respectively, the set of all bold and thin children of The following property of nice decompositions is extremely useful in designing the dynamic programming algorithms.  [24]) Let t be a node of a nice treecut decomposition of width k. Then |A t | ≤ 2k + 1.
Auxiliary problems and algorithms. To show that ComPath is fixed-parameter tractable with respect to the treecut-width we provide a dynamic-programming algorithm on the treecut decomposition. In the individual steps of the dynamic program we will need to solve the more general problem of finding compatible vertex-disjoint paths between given pairs of vertices. We now introduce this problem and a restricted variant that occurs in a special case of the dynamic program, and we provide a fixed-parameter algorithm for the more restricted variant.
Let G be a graph. We say that W is a set of terminal pairs of G, if it consists of pairwise-disjoint two-element subsets of V (G). If W is clear from the context, we also simply call the elements of W terminal pairs and each of them consists of terminals.
Recall that by T G we denote the transition system of G (again, we omit the subscript if it is clear from the context). Below we will also say that a set of pairwise disjoint paths as above is a solution to the instance (G, T G , W ). Clearly, an instance (G, T G , s, t) of ComPath is equivalent to an instance (G, T G , {{s, t}}) of ComVDP.
Our dynamic-programming approach is inspired by the XP-algorithm for finding edge-disjoint paths between given pairs of terminals, described by Ganian and Ordyniak [25]. However, we need modified dynamic-programming records and a more careful analysis to be able to ensure that subsolutions respect the transitions.
We first show fixed-parameter tractability of a simpler variant of ComVDP, called SComVDP, with additional assumptions on the structure of the input: Essentially, the vertex set is partitioned into a small set of arbitrary structure and a possibly large set of maximum degree two. A fixed-parameter algorithm for SComVDP will later be used when solving the general case. Observe that each instance of SComVDP has treecut-width at most |A|. Indeed, we may construct a treecut decomposition of G as follows: All vertices of A are contained in a bag X r and each vertex b ∈ B forms a separate bag X b . We define T to be a star, with r as its center and root. It is straightforward to verify that (T , {X t } t∈{r }∪B ) is a treecut decomposition of G of width |A|.
We now generalize the notion of suppressing a vertex to forbidden-transition graphs. Let (G, T ) be a forbidden-transition graph and v a vertex of degree at most 2 in G. If v is of degree 0 or 1, or T (v) does not contain any transition, we delete v. Otherwise, T (v) consists of a single transition, say {uv, vw}.
-If uw ∈ E(G), then we add an edge uw v , parallel to uw. Then, for each vertex Regardless of whether uw ∈ E(G), we remove v from G (and remove the corresponding transitions). Note that in ordinary graphs (without transitions), deleting a parallel edge preserves the existence of a solution that consists of pairwise vertex-disjoint edges. However, in our case we need parallel edges to handle transitions, see Fig. 4. Using them, the transitions in a forbidden-transition graph (G , T ) obtained from (G, T ) by suppressing v such that N G (v) = {u, w} are defined in such a way that we are allowed to use the original edge uw of G in a compatible path S in (G , T ) if and only if S is a compatible path also in (G, T ) or a path obtained from S by replacing the edge uw by two consecutive edges uv, vw is compatible in (G, T ). This implies that suppressing a non-terminal vertex v is a safe reduction rule, that is, it preserves the existence of a solution to ComVDP or SComVDP.
We are now ready to solve SComVDP. Proof Let J = (G, T , W ) be an instance of SComVDP. We start with simple sanity checks. First, observe that if |W | > n then J is clearly a no-instance as we cannot find more than n vertex-disjoint paths in G. Similarly, if there exists a vertex which belongs to more than one pair in W , then J must be a no-instance. Performing the sanity checks takes O(n 2 ) time.
Consider a vertex v ∈ B. If v does not belong to any pair in W and is not adjacent to any vertex by a parallel edge, then we suppress it. Recall that this preserves the solution. If v does not belong to any pair in W but is adjacent to a vertex by a parallel edge, we remove it, as it cannot be used by any path in a solution.
Therefore, we can assume that for each vertex v ∈ B there exists a unique vertex . If yes, we can safely remove v and v from G and {v, v } from W . Otherwise, we report that J is a no-instance -since all vertices in B are terminal vertices, there is no way to connect v and v . After this step, each vertex in B must have a neighbor in A. Moreover, observe that there is no {v, v } ∈ W such that v, v ∈ B and v ∈ N (v), so each path in a potential solution must intersect A.
Next, if |B| > 2|A| we report that J is a no-instance. Indeed, in order for J to be a yes-instance, since each vertex in B is a terminal, and each path in the solution containing a vertex of B must also contain a vertex of A, for each two vertices in B there must exist a vertex in A. Thus, |V (G)| ≤ 3k, and an algorithm guessing the partition of the vertex set into the desired paths solves the instance in k O(k) ·n O(1) time (as the number of edges in G is bounded by n 2 ). The statement now follows.
We emphasize that solving SComVDP will be the only moment where non-simple graphs (that is, graphs with parallel edges) appear in our algorithm. Since it will be used as a last step, to solve a reduced instance of the original problem, in the remaining part we describe the procedure only for simple graphs.
Before we proceed with the algorithm, we introduce a notion which will be useful when handling transitions. Let G be an induced subgraph of G. We say that a family set C i is either (i) a singleton or (ii) contains exactly two edges uu and vv such that u , v ∈ V (G ) and u = v . We omit reference to the graph G that contains G if it is clear from the context. We now define the operation of terminating a terminable set C. Intuitively, this operation returns a modified G in which all edges in the subsets of C are added and, if two edges were from the same subset of C, then their endpoints outside of G are merged into one vertex and the transition over this vertex is made to be allowed (see Fig. 5).

Definition 4.1
Let G be a simple graph with transition system T G . Consider an induced subgraph G of G and let C := {C 1 , . . . , C } be terminable with respect to G . We define the operation of terminating C in G which results in a graph G C with transition system T G C as follows. The resulting graph G C has vertex set V (G ) ∪ V , where the elements of V are c(C 1 ), . . . , c(C ). The edge set of G C is defined as follows.
and there exists an edge in C i adjacent to u in G}.
For simplicity we will sometimes write c i instead of c(C i ), if it causes no confusion.
The transition system T G C of G C is defined as follows.
-If u / ∈ V , then for w, z ∈ N (u) a transition {wu, uz} belongs to T G C (u) if and only if w, z / ∈ V and {wu, uz} ∈ T G (u), or w / ∈ V , z = c i ∈ V and {wu, e} ∈ T G (u), where e is the unique edge from C i adjacent to u, or , where e and f are, respectively, the unique edges from C i and C j adjacent to u.
-If u = c i ∈ V , then T G C (u) contains all unordered pairs of edges incident with u.
Note that since each C i has at most 2 elements, all vertices from V have degree at most 2.
Observe that after terminating some C in G , we always obtain a simple graph. Moreover, the following observation is straightforward. Algorithm overview. The algorithm will compute the solution to ComVDP by dynamic programming over (T , X ) in a leaf-to-root fashion. In a fixed node t of T , we consider the possible partitions of E t into four sets I (internal), F (foreign), L (leaving), and U (unused). Intuitively, the edges in sets I , F, and L will correspond to edges in the solution paths: paths with both terminals in Y t use edges in I , paths with both terminals in Z t use edges in F and paths with one terminal y ∈ Y t and another one z ∈ Z t use one edge of L (which is supposed to be the first edge on the solution path from y to z which belongs to E t ) and their other edges should belong to F. For each such partition we consider all possible records, that is, ways in which a potential solution could behave on E t (see Definition 4.2).
If now t is a leaf, for every such record we check whether it is valid, i.e., whether we can extend the potential solution corresponding to it to a graph created from the input graph G by terminating some family of subsets of E t with respect to G[X t ]. This can be done using an algorithm that solves SComVDP. Otherwise, t has a child t . If t is thin, we use a reduction rule to handle it. If t is bold, for each valid record of t , we perform a simplification -we terminate some family of subsets of E t with respect to G[Z t ]. Then, after simplifying every bold child of t, we can again check whether it is valid, by terminating some family of subsets of E t and solving SComVDP.
Notions for dynamic programming. We now introduce the notions used in our dynamic-programming approach and give results that we will later need to prove the correctness. Let (G, T G , W ) be an instance of ComVDP and let (T , X ) be a treecut decomposition of G of width k. For a set X ⊆ V (G), by W [X ] we denote the subset of terminal pairs from W with both elements in X . For a node t ∈ V (T ) An unmatched terminal for t is a vertex x ∈ Y t such that there exists a vertex y ∈ Z t satisfying {x, y} ∈ W . We let U t be the set of unmatched terminals for t. We will use the fact that the number of unmatched terminals is bounded by the width of (T , X ) in every yes-instance:

Observation 4.4 If (G, T G , W ) is a yes-instance, then for each node t of T the number |U t | of unmatched terminals is at most k.
Proof Consider a solution to the instance and observe that this solution witnesses that there is a flow between U t and Z t of value at least |U t |. Since E t is a Y t -Z t cut in G containing at most k edges and U t ⊆ Y t , we have |U t | ≤ |E t | ≤ k.
Since Observation 4.4 is easily checkable in polynomial time, we will from now on assume that for each node t of T we have |U t | ≤ k.
As mentioned, we are going to describe a dynamic-programming procedure on the treecut decomposition (T , X ). Below we introduce a basic notion which will be used to store the information about partial solutions. a tuple (σ, I, F, λ) consisting of the following elements.

Definition 4.2 A record R for t ∈ V (T ) is
-Function σ is a partition of E t into sets I (internal), F (foreign), L (leaving), and U (unused), such that for every belong to exactly one of I or F, or (ii) v ∈ Z t and one element of E(v) ∩ (I ∪ F ∪ L) belong to to F and another one to L. -Set I is a perfect matching between the elements from I , such that if {y i z i , y j z j } ∈ I then y i = y j (recall that y i , y j denote vertices in Y t and z i , z j vertices in Z t ). -Set F is a perfect matching between the elements from F, such that if {y i z i , y j z j } ∈ F then z i = z j . -Finally, λ is a bijection between U t and L.
Observe that the conditions on σ together with the conditions on the matchings I and F ensure that I ∪ {{e} : e ∈ F ∪ L} is terminable with respect to the subgraph G[Y t ] of G and that F ∪ {{e} : e ∈ I ∪ L} is terminable with respect to the subgraph G[Z t ] of G.
Let R(t) denote the set of all possible records for t. Observe that |R(t)| ≤ 4 k ·(k!) 3 = k O(k) , as there are at most 4 k possibilities for σ , there are at most k! possibilities each for the matchings I and F, and at most k! possibilities for λ because there are at most k unmatched terminals by Observation 4.4.
Intuitively, the matchings should capture, in case of edges in I , which edge is used by path to leave Y t and then to come back, and in case of edges in F, by which edge we enter Y t and which one is then used to leave. Finally, λ says by which edge we leave Y t for the first time. Below we introduce a notion which will help to formalize this intuition. (G, T , W ), a node t of a treecut decomposition (T , X ) of G and a record R = (σ, I, F, λ) ∈ R(t), we construct a corresponding instance (G R , T R , W R ) of ComVDP as follows. Let C = {C 1 , . . . , C } := I∪{{e} : e ∈ F ∪L}. Let the graph G R , together with the transition system T R , be obtained by terminating

Definition 4.3 For an instance
Note that the set C was defined in such a way that the pairs added to W R are disjoint.
A record R is valid, if its corresponding instance (G R , T R , W R ) is a yes-instance of ComVDP. A corresponding instance should capture how the potential solution we construct behaves on G t .

Definition 4.4
Let (T , X ) be a treecut decomposition of G, let t ∈ V (T ) and let J = (G, T , W ) be an instance of ComVDP. Assume that there exists a solution S = {P 1 , P 2 , . . . , P |W | } to J . We say that solution S corresponds to a record (σ, I, F, λ) for the node t, if the following conditions are satisfied for every a i -b i path P i ∈ S such that E(P i ) ∩ E t = ∅. Let e i 1 , e i 2 , . . . , e i r i denote the elements of P i ∩ E t in the order of their appearance on P i .
then λ(a i ) = e i 1 (note that in this case a i is an unmatched terminal, that is, a i ∈ U t ) and {e i j , e i j+1 } ∈ F for each even j ∈ [r i − 1].

An edge e ∈ E t belongs to U if and only if e / ∈ i∈[|W |] E(P i ).
The dynamic-programming procedure on the treecut decomposition (T , X ) of G computes the set D(t) of valid records for a node t of T . In other words, in D(t) we store the information about these behaviors of a potential solution on E t , which can be extended to G t . Note that (G, T , W ) is a yes-instance of ComVDP if and only if D(r ) = {(∅, ∅, ∅, ∅)}.
The last operation which will be used in the algorithm is the simplification of an instance. Intuitively, for a record R, the simplified instance is a smaller instance of the ComVDP problem which is equivalent to the original instance J assuming that, if J is an yes-instance, then R corresponds to some solution for J . Note that the construction of the simplified instance can be seen as dual to the construction of the corresponding instance.
Observe that each vertex in V Q has degree at most 2, and the degree of vertex in V (G Q ) \ V Q is at most its degree in G.
The following lemmata reveal how the introduced notions are related to each other.

Lemma 4.5 Let (T , X ) be a treecut decomposition of G and let J = (G, T , W ) be an instance of ComVDP which admits a solution S. Then for every node t ∈ V (T ) there exists a unique record R ∈ R(t) such that S corresponds to R. On the other hand, if S corresponds to some record R, then R must be valid.
Proof It is clear that for a fixed S and t there exists an unique R = (σ, I, F, λ) ∈ R(t) satisfying conditions 1.

If J Q admits a solution and R is valid, then J admits a solution. 2. If S is a solution to J and S corresponds to R, then J Q admits a solution.
Note that in both statements of the lemma, R must be valid -in the first one by assumption and in the second one it follows from Lemma 4.5. Let thus J R = (G R , T R , W R ) be a yes-instance corresponding to R, obtained by terminating , . . . , c (C )} (we will also write c i instead of c (C i )) and let S R be a solution to J R .
For the first statement, assume that S Q is a solution to J Q . For each {a, b} ∈ W we construct a compatible a-b path P * to include in a solution for J as follows. We iteratively construct a sequence P * of elements of V (G R ) ∪ V (G Q ) with the property that, at each iteration, two consecutive vertices of P * either form an edge from E(G R ) ∪ E(G Q ) or from E t . We claim that, at the end of the procedure, P * is a compatible a-b path in G.
We first consider the case in which a, b ∈ Y t . Observe that there is an a-b path P ∈ S R in G R . We start with P * being the consecutive vertices of P. If there are no vertices from the set V R in P, then P * is the desired a-b path in G. Otherwise, we proceed to Step 1.
Step 1 (Replacing vertices from V R ): Denote by e 1 , e 2 , . . . , e m the edges from E(Y t , V R ) ∩ E(P) in the order in which they appear on P. Since a, b ∈ Y t and by the construction of J R we must have {e 1 , e 2 }, {e 3 , e 4 }, . . . , {e m−1 , e m } ∈ I. This implies that for each i ∈ {1, 3, . . . , m − 1} there exists a c({e i })-c({e i+1 }) path in S Q ; call this path P i,i+1 . We replace each element of V R adjacent to edges e i and e i+1 in P * by the interior vertices of P i,i+1 . Observe that the result respects the transitions of G by the definition of termination of a set. Observe that in this way we may have added some vertices from V Q to the sequence P * . If this has happened, we take care of them in Step 2.
Step 2 (Replacing vertices from V Q ): Let e 1 , e 2 , . . . , e m be the edges from E(Z t , V Q ) ∩ E(P i,i+1 ) in the order in which they appear on P i,i+1 . By the construction of J Q we have {e 1 , e 2 }, . . . , {e m −1 , e m } ∈ F. Moreover, for each j ∈ {1, 3, . . . , m − 1} there exists a c ({e j })-c ({e j+1 }) path P j, j+1 in S R . We replace each element of V Q adjacent to edges e j and e j+1 in P * by the interior vertices of the c({e j })-c({e j+1 }) path P j, j+1 from S R . Observe again that the result respects the transitions of G by the definition of termination of a set. Again, in Step 2 we can add to the sequence some vertices from V R . If this happens, we go back to Step 1.
Since the paths in S R and S Q are pairwise disjoint, we never add a vertex to P * twice. Moreover, |V R |, |V Q | ≤ k, so after at most 2k iterations, we obtain an a-b path P * which uses only vertices from Y t ∪ Z t , as required.
The case in which a, b ∈ Z t is analogous; the only difference is that the initial path P * is taken from S Q , and therefore it can contain vertices from V Q and, in that case, we start with Step 2. If a ∈ Y t and b ∈ Z t , we start with the c ({λ(a)})-b path P * from S Q and, before performing Step 1, we replace c ({λ(a)}) in P * by the vertices of the a-c({λ(a)}) path in S R .
It is straightforward to verify that we use every path from S R and S Q at most once when we construct paths for all terminal pairs {a, b}. Therefore, since S R and S Q are sets of pairwise vertex-disjoint paths, we obtain a set S of pairwise vertex-disjoint paths in G connecting each pair in W .
For the second statement, observe that if S is a solution to J , then we can derive a construction of every a-b path in G Q from Observation 4.3 (analogously to the proof of Lemma 4.5).
The algorithm. We are now ready to show how to proceed with a given instance Observe that if t is a leaf of T and R ∈ R(t), the corresponding instance (G R , T R , W R ) of R is an instance of SComVDP. Indeed, since Y t = X t , Y t has at most k elements and the vertices in V R are of degree at most 2. This means that to compute the set D(t) for a leaf t, for every element R of R(t) we find a corresponding instance and solve SComVDP on it. Since |R(t)| ≤ k O(k) , we obtain the following.

Lemma 4.7 There is an algorithm which takes as input a ComVDP instance (G, T G , W ), a treecut decomposition (T , X ) of G of width k and a leaf t ∈ V (T ), and computes D(t) in time k
Next, we proceed to the non-leaf nodes. A dynamic programming step will consist of three stages. For a non-leaf node t, we again construct a corresponding instance, but since its size does not have to be bounded by some function of k, we apply some further modifications. First, we apply a reduction rule for each of the thin children (see below). Then we perform a simplification for each bold child t of t and each R ∈ R(t). After these, we argue that the graph obtained this way (for a fixed record R) is again an instance of SComVDP, which can be solved efficiently.
Assume we solve an instance (G, T G , W ) and let t ∈ V (T ) be a non-leaf node. The safeness of the following reduction rule follows directly from its definition.

Reduction Rule 1 Assume that T is a nice decomposition and let s ∈ V (T ) be a thin child of t. If D(s) is empty, we report a no-instance.
Otherwise, we proceed with the first option that applies on the following list. Herein, by terminating a terminable set C, we mean to replace G by the result of the termination of C with respect to G[Z s ].

In all other cases, we report that (G, T , W ) is a no-instance.
Finally, we are ready to prove the following.

Lemma 4.8 There is an algorithm which takes an instance J = (G, T , W ) of ComVDP, a nice treecut decomposition (T , X ) of G of width k and a non-leaf node t ∈ V (T ), and computes D(t) in time k O(k) · n 2 , assuming that for each child t of t the set D(t ) is already computed.
Proof First, we loop over all possible R ∈ R(t); recall that |R(t)| ≤ k O(k) . For a fixed R, we compute the corresponding instance J R = (G R , T R , W R ) of ComVDP. Recall that V R is a subset of vertices of G R , which was added to G t during the construction of J R and each vertex in V R has degree at most two. For the computed instance J R , we apply the above reduction rule for each of the thin children of t ∈ V (T ). Note that each vertex v added to G R during any of these reductions for thin children (denote the set of these vertices by B B ) is of degree at most two. Moreover, since the treecut decomposition of our graph is nice, Then we loop over all possible functions μ that map each element t of A t to some element of D(t ). By Theorem 4.5, there are at most 2k + 1 elements of A t , so there are at most (k O(k) ) 2k+1 = k O(k 2 ) such functions. For the current R and μ, we perform for each t ∈ A t the simplification according to μ(t ). Denote by J = ( G, T , W ) the instance obtained from J R after applying this sequence of simplifications (i.e., G is induced by vertices from X t ∪ V R ∪ B B and all V Q 's coming from the simplifications).
We claim that J is an instance of SComVDP. Indeed, we observed that after the simplification process, the degree of a vertex which was not added during the procedure is at most its degree in the original graph. So the only vertices which might have degree bigger than 2 are the ones which belong to X t . We thus can compute whether J is a yes-instance in k O(k) + O(n 2 ) time using Lemma 4.2.
We claim that J is a yes-instance if and only if R is valid. To see that, first assume that R ∈ R(t) is a valid record. Thus J R admits a solution. By Lemma 4.5, this means that there exists a valid record R t ∈ D(t ) for each child t of t. The reduction rule for thin children is safe and thus the solution is preserved. For the bold children, consider an iteration in which μ assigns R t to t , for each t ∈ A t . The second statement of Lemma 4.6 implies that the sequence of simplifications (starting from the instance J R ), consecutively in each node t ∈ A t , preserves the existence of a solution, so J is a yes-instance of SComVDP.
Conversely, assume that the algorithm adds R to D(t), so the instance J of SComVDP is a yes-instance. Then by the first statement of Lemma 4.6, all the instances obtained in the sequence of simplifications are also yes-instances. Since the reduction rule for thin children is safe, the corresponding instance J R of R must be also a yes-instance. Therefore, our algorithm computes correctly the set of valid records for t.
The procedure takes time k O(k 2 ) times the time needed to solve an instance of SComVDP; together k O(k 2 ) · n 2 .
We conclude the section with the following theorem.

Edge-Colored Graphs and Treewidth
Our main result on properly colored paths and cycles in edge-colored graphs of bounded treewidth is as follows:

Theorem 4.7 Given an undirected graph G with an edge coloring λ : E(G) → [ ] and a tree decomposition (T , β) of G of width less than k, one can verify if G admits a properly colored Hamiltonian Cycle in deterministic time 2 O(k) ·O(|V (G)|+|V (T )|+
).
The main highlight of Theorem 4.7 is the lack of the dependency on in the exponential part of the running time bound (see below as to why this is). For sake of simplicity, we do not analyze in detail the base of the exponent in the running time bound of the algorithm of Theorem 4.7.
The structure of the algorithm of Theorem 4.7 follows the outline of the typical rank-based algorithms for connectivity problems on graphs of bounded treewidth [11]. We refer to [15,Chapter 11] for an exposition of the rank-based approach in the case of Steiner Tree and to [53] for a different short exposition of the presented approach for Hamiltonian Cycle.
We start with describing a naive approach and then show how to reduce its complexity.
A separation of a graph G is a pair (A, B) G and (A, B) a partial solution for (A, B). If P is a partial solution for (A, B) and Q is a partial solution for (B, A), then we say that P and Q fit each other if P ∪ Q is a Hamiltonian cycle in G.
The trace of a partial solution P for (A, B) is The following observation is straightforward.

Lemma 4.9 If P is a partial solution for (A, B) and Q is the partial solution for (B, A), then P fits Q if and only if the trace of P fits the trace of Q.
Lemma 4.9 is the base of the naive algorithm for Hamiltonian cycle on graphs of bounded treewidth. Given a tree decomposition (T , β), where T is a rooted tree, for a node t ∈ V (T ) we use the following notation: -V t is the union of β(s) over all descendants s of t (including t), Note that This naive algorithm can be easily adjusted to accommodate edge colors. Assume that we are given an edge coloring λ : E(G) → [ ] and look for a properly colored Hamiltonian cycle. In the definition of a partial solution, we require all paths of P to be properly colored. Furthermore, partial solutions P for (A, B) and Q for (B, A) fit each other if their union is a properly colored Hamiltonian cycle, that is, for every vertex v ∈ V (A) ∩ V (B) that is an endpoint of both a path of P and a path of Q, the edge of P incident with v and the edge of Q incident with v are of different colors. To accommodate this, the colored trace for a partial solution P is a triple ( f P , M P , ζ P ) where f P and M P have the meaning as before and ζ P : . Again, we have a straightforward analog of Lemma 4.10:

Lemma 4.10 If P is a partial solution for (A, B) and Q is the partial solution for (B, A) in an edge-colored graph G, then P fits Q if and only if the colored trace of P fits the colored trace of Q.
Note that there are at most 2 O(k log k) k possible colored traces for a separation of order at most k. By following the standard dynamic programming algorithm for Hamiltonian cycle on graphs of bounded treewidth (see e.g. [53]), we obtain the following. We now introduce the rank-based approach . Fix a separation (A, B) and fix a

Lemma 4.12 Assume that A is a family of traces for (A, B) with the same first coordinate f . If A ⊆ A is such that C[A , ·] spans the same subspace as C[A, ·], then A represents A.
Consequently, we can improve the naive algorithm for the Hamiltonian Cycle problem as follows. At node t ∈ V (T ), replace A(t) with a subset A (t) representing A(t) as folows: for every possible f : β(t) → {0, 1, 2}, restrict A(t) to A(t, f ) consisting of traces with the first coordinate f , compute A (t, f ) ⊆ A(t, f ) representing A(t, f ) using Lemma 4.12 and a Gaussian elimination on C[A(t, f ), ·] over F 2 , and declare By now-standard methods (see, e.g., the exposition of [53]), one can compute in a bottom-up fashion representatives A (t) for t ∈ V (T ); the computation at note t takes into account the representatives at children of t and takes time 2 O(k) per child.
By following the same outline, to prove Theorem 4.7, it suffices to show the following: A be a family of colored traces for (A, B). Then, there exists a polynomial-time algorithm that, given A and integers k and , finds a subset A ⊆ A that represents A and is of size at most 6 k .

Lemma 4.13 Let G be a graph with edge coloring λ : E(G) → [ ], (A, B) be a separation of order k, and
By partitioning A according to the first coordinate, it suffices to prove the following:  {0, 1, 2}, and A be a family of colored  traces for (A, B) with the first coordinate f . Then, there exists an algorithm that, given A, f , and integers k and ,in time polynomial in the input size and 2 k , finds a subset A ⊆ A that represents A and is of size at most 4 k .
The rest of this section is devoted to the proof of Lemma 4.14.
Let a be such that 2 a > and let F = F 2 a be the field of characteristic 2 with 2 a elements. Operations on F can be done in time polynomial in a = O(log ). Furthermore, F 2 ⊆ F. We replace the range of colors [ ] with non-zero elements of F: for every color i ∈ [ ] we pick a distinct non-zero element a i ∈ F. Henceforth, we assume that λ and all functions ζ P for ( f , Note that π can be treated as a 2|Z |-variate multilinear polynomial of degree |Z | with variables (ζ P (v)) v∈Z and (ζ Q (v)) v∈Z . Furthermore, we have that For a function ζ P : Z → F, define a |Z |-variate multilinear polynomial  τ for (A, B) and E[τ, ·] is the tensor product of C [τ, ·] and D[τ, ·]. Note that E has 2 |Z |−1 · 2 |Z | = 2 2|Z |−1 columns. Lemma 4.14 follows from the following lemma by applying Gaussian elimination on the rows of E corresponding to the elements of A. Let v 2 be a vector over F with elements indexed by all 2 |Z | multilinear monomials over variables (x v ) v∈Z ; the value of v 2 at monomial v∈I x v for I ⊆ Z equals Consequently, for a colored trace τ = ( f , M R , ζ R ), we have that τ fits τ Q if and only if C [τ, ·]·v 1 = 0 and D[τ, ·]·v 2 = 0. The latter is equivalent to E[τ, ·]·(v 1 ⊗v 2 ) = 0, where v 1 ⊗ v 2 is the tensor product of v 1 and v 2 . Since spans the same subspace as E[A, ·], there exist elements τ 1 , τ 2 , . . . , τ r ∈ A and coefficients λ 1 , . . . , λ r , such that Hence, τ i fits τ Q and we have τ i ∈ A . This finishes the proof of the lemma.
Recall that E has 2 2|Z |−1 ≤ 4 |Z | columns. Hence, with Gaussian elimination one can find A as in Lemma 4.15 of size at most 4 |Z | . This finishes the proof of Theorem 4.7.

Two Disjoint Shortest Paths
In this section, we present polynomial-time algorithms for vertex-disjoint and edgedisjoint cases of 2-DSPP with transition restrictions when every directed cycle has positive length. First, we give the formal definition of this problem.
Directed Two Disjoint Shortest Paths Problem (2-DSPP) with transition restrictions Input: A directed graph G = (V , E) with transition system T , a length function w : E → R ≥0 and two pairs of vertices (s 1 , t 1 ),(s 2 , t 2 ) in G.
Task: Find two disjoint (vertex-disjoint or edge-disjoint) paths P 1 and P 2 in G such that for both i = 1, 2, path P i is a shortest path (even in the graph G with no transition restrictions) from s i to t i and P i is also T -compatible.
Our algorithm is an adaption of the algorithm for Directed Two Disjoint Shortest Paths Problem (assuming that every dicycle in G has positive length) of Bérczi and Kobayashi [9], which reduces the problem of Edge Disjoint 2-DSPP to finding a path in a graph G constructed from the input graph G. Roughly speaking, we show that transition restrictions are not a barrier for using the same strategy. Note that in this section we consider directed graphs with parallel edges. Transitions and transition systems for directed graphs are defined in the natural way analogous to the undirected case.
We follow the notations from the paper of Bérczi and Kobayashi [9] for convenience. We define E i to be the set of edges that appear in some shortest path (without transition restrictions) from s i to t i for i = 1, 2. By this definition, an s i -t i path is a shortest Tcompatible s i -t i path if and only if it consists of edges of E i and is also T -compatible for i = 1, 2. Thus the edge-disjoint (vertex-disjoint) 2-DSPP with transition restrictions is equivalent to finding two edge-disjoint (vertex-disjoint) T -compatible paths P 1 and P 2 such that P i is from s i to t i , E(P i ) ⊆ E i and P i satisfies the transition restrictions for i = 1, 2. Each set E i can be computed in polynomial time using the method from the paper of Bérczi and Kobayashi [9]. First, we compute the distance d i (v) from s i to v for i = 1, 2, using Dijkstra's algorithm.

Edge-Disjoint Case
We show that the edge-disjoint case of 2-DSPP with transition restrictions can be solved in polynomial time. We use the method of Bérczi and Kobayashi [9], which reduces the problem of Edge Disjoint 2-DSPP to finding a path in an auxiliary graph G suitably constructed from the input graph G. Based on that, we just need to delete edges of G which correspond to forbidden transitions of G with respect to T and it suffices to find the path in the remaining subgraph of G.
Ordinary graphs. We repeat the procedure of Bérczi and Kobayashi [9] briefly here for consistency (see Fig. 6). Let G be a graph (without transition systems T ) such that the length of every dicycle in G is positive. First, we compute E i for i = 1, 2. Then we create four new vertices s 1 , s 2 , t 1 , t 2 , create four edges s 1 s 1 , s 2 s 2 , t 1 t 1 , t 2 t 2 of length 0 respectively, and add s i s i , , contract all edges of E 0 and reverse all edges of E * 2 . Finally we get a new graph G * = (V * , E * = E * 1 ∪ E * 2 ). Let V 0 ⊆ V be the set of vertices that are newly created after contracting E 0 . For v ∈ V 0 , we use G v to denote the subgraph of G − (E(G) \ (E 1 ∪ E 2 )) induced by the vertices corresponding to v before contracting. For an edge e ∈ E * , let f (e) ∈ E(G) be the edge corresponding to e before the contracting and reversing operations. Fig. 6 A digraph G and its corresponding graph G * (to simplify the picture, we omitted the lengths of edges). Here, edges in E 1 are fat, and the edges of E 2 are dashed. Set V 0 is a singleton, denoted by gray vertex s 2 , that corresponds to the gray subgraph G s 2 of G Fig. 7 A path in G that corresponds to the solution of the instance G depicted in Fig. 6 Note that s i , t i ∈ V (G) might be the endpoints of edges of E 0 for i = 1, 2. In this case, although we might contract the edges incident to s i , t i ∈ V (G) and replace these vertices with new vertices. Therefore, we slightly abuse the notation and use s i and t i to denote the vertex adjacent to s i and t i respectively in G * for i = 1, 2, for the sake of simplicity.
The following two lemmas show that G v is acyclic for every v ∈ V 0 and G * is acyclic.
Lemma 5.2 (Bérczi,Kobayashi,[9]) In the graph G, suppose that C is a dicycle in Then we define a new digraph G whose vertex set is W = E * 1 × E * 2 . There is a directed edge from (e 1 , e 2 ) to (e 1 , e 2 ) if one of three cases holds.
(i) e 1 = e 1 and head G * (e 2 ) = tail G * (e 2 ) = v. There is no path from head G * (e 1 ) to v in G * . Moreover, if v ∈ V 0 , then G v contains a path from tail G (e 2 ) to head G (e 2 ). (ii) e 2 = e 2 and head G * (e 1 ) = tail G * (e 1 ) = v. There is no path from head G * (e 2 ) to v in G * . Moreover, if v ∈ V 0 , then G v contains a path from head G (e 1 ) to tail G (e 1 ).
contains two edge-disjoint paths from head G (e 1 ) to tail G (e 1 ) and from tail G (e 2 ) to head G (e 2 ) respectively.
Finally the following lemma reduces the edge-disjoint version of 2-DSPP to finding a path in G from (s 1 s 1 , t 2 t 2 ) to (t 1 t 1 , s 2 s 2 ) (see Fig. 7). Lemma 5.3 (Bérczi,Kobayashi,[9]) There is a directed path in G from (s 1 s 1 , t 2 t 2 ) to (t 1 t 1 , s 2 s 2 ) if and only if G has two edge-disjoint paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2.
Handling transitions. To solve the edge-disjoint version of Directed Two Disjoint Shortest Paths Problem (2-DSPP) with transition restrictions, we will show that it suffices to (i) delete these edges in G that correspond to forbidden transitions (or non-T -compatible paths) of G, and (ii) find a path in the remaining graph of G from (s 1 s 1 , t 2 t 2 ) to (t 1 t 1 , s 2 s 2 ). For every edge in G, we check whether it corresponds to forbidden transitions according to the following three cases and delete the edge if it corresponds to forbidden transitions. Suppose the edge is from some vertex (e 1 , e 2 ) ∈ W to another vertex (e 1 , e 2 ) ∈ W .
• The edge is of type (i), i.e., e 1 = e 1 and head G * ( . In this case, if G s does not contain two T -compatible edge-disjoint paths such that one path is from tail G ( f (e 1 )) to head G ( f (e 1 )) and the other path is from tail G ( f (e 2 )) to head G ( f (e 2 )), then remove the edge from G.
, then remove the edge from G.
We need to check whether there exists a T -compatible path between two given vertices in a (direced) forbidden-transition graph. Szeider shows a dichotomy of NPcomplete and linear-time solvable for the problem of finding a T -compatible path between two given vertices of an (undirected) graph [49]. In contrast, the following lemma shows that in a directed acyclic graph, we can find a T -compatible path between two given vertices in polynomial time.

Lemma 5.4 In a directed acyclic graph G = (V , E) with transition system T G , we can compute if there is a directed T -compatible path P from s to t for s, t ∈ V (G) in polynomial time.
Proof We construct a directed graphG as follows. First create two vertices s 0 , t 0 . Then for every edge e ∈ E(G), create a vertex v e . For any two edges e, e ∈ E(G), create an edge v e v e if ee ∈ E(T G (v)) for some v ∈ V (G). Finally, create edges s 0 v e for every e ∈ E(G) such that tail G (e) = s and create edges v e t 0 for every e ∈ E(G) such that head G (e ) = t. We claim that we can find a directed path P from s 0 to t 0 inG if and only if there is a directed T -compatible path P from s to t in G. For the "if" direction, suppose that there is such a path P = e 1 , e 2 , . . . , e in G, where e 1 , . . . , e are the consecutive edges of P. Then we can obviously get the path P = s 0 v e 1 , v e 1 v e 2 , . . . , v e t 0 by the definition ofG. For the "only if" direction, suppose that there is a directed path P = s 0 v e i 1 , v e i 1 v e i 2 , . . . , v e i t 0 inG. Then P = e i 1 , e i 2 , . . . , e i is a directed T -compatible walk from s to t in G. Since G is acyclic, P is also a path. This completes the proof of the claim. We can build the graph G in O(|E| 2 )-time and find an s 0 t 0 path inG using DFS in O(|E| 2 ) time. Thus the lemma holds.
For v ∈ V 0 , by Lemma 5.1, there is no dicycle in G v . Moreover, observe that we cannot have a vertex in V (G) \ V (G v ) adjacent to more than one edge from E(G s ) \ E(G v ), so G s is also acyclic. So we can decide whether or not to remove the edges of type (i) or (ii) from G in polynomial time according to Lemma 5.4. For the edges of type (iii), we need to compute if there are two edge-disjoint T -compatible paths in a directed acyclic graph. We show that it can be done in polynomial time and the algorithm is an adaption of the algorithm of finding two vertex-disjoint paths in DAG by Perl and Shiloach [47]. Proof First we modify the graph G as follows. We create four vertices s 1 , s 2 , t 1 , t 2 and (1) e 1 = e 1 , (head G (e 2 )) ≥ (head G (e 1 )), {e 2 , e 2 } ∈ T G (head G (e 2 )).
We claim that there are two T -compatible edge-disjoint paths P 1 and P 2 in G such that P i is from s i to t i for i = 1, 2 if and only if there is a path P from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) inG. • j = q + 1 and i ≤ p, (head G (e i 1 )) < (t 2 ) and there is an edge inG from (e i 1 , e q+1 2 ) to (e i+1 1 , e q+1 2 ). As a result, there is a path P from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) inG. This finishes the proof for "only if" direction.
("if" direction): Suppose that there exists a path P from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) inG. Let P = (e 0 1 , e 0 2 ), (e 1 1 , e 1 2 ), . . . , (e r 1 , e r 2 ) such that (s 1 s 1 , s 2 s 2 ) = (e 0 1 , e 0 2 ) and (e r 1 , e r 2 ) = (t 1 t 1 , t 2 t 2 ). We construct two edge-disjoint T -compatible paths P 1 , P 2 as follows. First we initialize P 1 = e 0 1 , P 2 = e 0 2 . Then for i = 0, . . . , r − 1, we update P 1 and P 2 according to the following cases: is of type (4). Then P 1 ← P 1 · e i+1 1 . By the definition of edges ofG, we get that P 1 and P 2 are two T -compatible edgedisjoint paths in G such that P i is from s i to t i for i = 1, 2. We can construct a graph G in O(|E| 3 ) time and find a path from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , Thus the lemma holds. Thus we can also decide whether or not to remove an edge of type (iii) from G in polynomial time and letĜ be the remaining subgraph of G. The following lemma shows that we can reduce edge-disjoint version of 2-DSPP with transition restrictions to finding a path from (s 1 s 1 , t 2 t 2 ) to (t 1 t 1 , s 2 s 2 ) inĜ.

Lemma 5.6
There is a directed path inĜ from (s 1 s 1 , t 2 t 2 ) to (t 1 t 1 , s 2 s 2 ) if and only if G has two edge-disjoint T -compatible paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2.
Proof ("if" direction) Suppose that G has two edge-disjoint T -compatible paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2. E(P 1 )\E 0 forms a directed path P * 1 in G * from s 1 to t 1 . E(P 2 ) \ E 0 forms a directed path P * 2 in G * from t 2 to s 2 .  {0, ..., p}, j ∈ {0, ..., q})). Since P 1 and P 2 are T -compatible, by the rules we constructĜ, we can see that all edges of P in G remains inĜ. This completes the proof for "if direction".
("only if" direction) Suppose that there is a directed path P from (e 0 1 , e 0 2 ) = (s 1 s 1 , t 2 t 2 ) to (e r 1 , e r 2 ) = (t 1 t 1 , s 2 s 2 ) inĜ that goes through (e 0 1 , e 0 2 ), (e 1 1 , e 1 2 ), . . ., (e r 1 , e r 2 ) consecutively. SinceĜ is a subgraph of G, by Lemma 5.3, there exists two edge-disjoint paths P 1 and P 2 in G such that P i is from s i to t i and P i ⊆ E i for i = 1, 2 in G. Moreover, again from the proof of Lemma 5.3, it follows that e i 1 ∈ E(P 1 ) and e i 2 ∈ E(P 2 ). By the rule we constructĜ, for an edge from (e i 1 , It follows that P 1 and P 2 are also T -compatible. This finishes the proof for "only if" direction.
SinceĜ is a subgraph of G and G contains at most |E| 2 vertices, we can detect a path inĜ in polynomial time. Thus Lemma 5.6 shows that we can solve edge-disjoint version of 2-DSPP with transition restrictions in polynomial time assuming that every cycle in the input graph has positive length.

Vertex-Disjoint Case
When computing vertex-disjoint version of 2-DSPP in the paper of Bérczi and Kobayashi [9], they create a new digraph G 2 as follows: for every vertex v ∈ V create two vertices v + and v − . Create an edge v − v + with w(v − v + ) = 0. Create an edge u + v − if there is an edge uv in G and let w(u + v − ) = w(uv). Thus vertex-disjoint 2-DSPP in G is reduced to edge-disjoint variant of 2-DSPP in G 2 . However, this method does not work in the forbidden-transitions setting because part of the information of transitions will be lost after creating the new graph G 2 .
In order to keep the information of transitions, we first modify G as follows. We compute the set E 1 and E 2 of G. Remove all edges of E(G) \ (E 1 ∪ E 2 ) from E(G) and all isolated vertices from V (G). When removing the edges or vertices we update the transition system accordingly. Then create four new vertices s 1 , s 2 , t 1 , t 2 and four edges s 1 s 1 , s 2 s 2 , t 1 t 1 , t 2 t 2 all with length 0. Add s i s i and t i t i to E i for i = 1, 2. Thus a shortest path from s i to t i corresponds to a shortest path from s i to t i starting with the edge s i s i and ending with the edge t i t i . We update T G (s i ) by adding {{e, e } | e = s i s i and tail G (e ) = s i } to it for i = 1, 2. Let T G (t i ) = {{e, e } | head G (e) = t i and e = t i t i } for i = 1, 2.
Then we create a graph G as follows. For every vertex v ∈ V (G) \ {s 1 , s 2 , t 1 , t 2 }, create two vertices v + and v − . We also create four vertices s 1 , s 2 , t 1 , t 2 in G and create four edges s 1 s − 1 , s 2 s − 2 , t + 1 t 1 , t + 2 t 2 in G all with length 0. For every vertex v ∈ V (G) \ {s 1 , s 2 , t 1 , t 2 }, let in 1 (v), . . . , in r v (v) be the incoming edges of v. Then create r v parallel edges e 1 (v), . . . , e r v (v) with tail G (e j (v)) = v − and head G (e j (v)) = v + in G for j = 1, . . . , r v such that each of the edges is of length 0. If there is an edge uv = in p (v) in G for some p ∈ [r v ] and u, v / ∈ {s 1 , s 2 , t 1 , t 2 }, create an edge in p (v − ) = u + v − in G and let w(u + v − ) = w(uv). Next, we define the transition system for G as follows.
We also need to compute the set of edges E i that exist in some shortest path (without transitions) from s i to t i for i = 1, 2. By this definition, obviously  (Bérczi,Kobayashi,[9]) In the graph G , suppose that C is a dicycle in We contract all edges of E 0 and get a graph G = (V , E ). For an edge e ∈ E , let f (e) ∈ E(G ) denote the edge corresponding to e before the contracting operations. We need to compute the new transition system of G as follows. Let V 0 ⊆ V be the set of vertices that are newly created after contracting E 0 . For v ∈ V 0 , we use G v to denote the subgraph of G −(E(G )\(E 1 ∪ E 2 )) induced by the vertices corresponding to v before contracting.
If there is a T -compatible path in the subgraph of G consisting of all edges of G v together with f (e) and f (e ) from tail G ( f (e)) to head G ( f (e )), then {e, e } ∈ T G (v). By Lemma 5.8, there is no dicycle in G v . Moreover, the subgraph of G consisting of all edges of G v together with f (e) and f (e ) is also acyclic. So we can compute T G (v) for every v ∈ V 0 in polynomial time according to Lemma 5.4. Since E * 1 ∩ E * 2 = ∅, then we can reverse all edges of E * 2 (the lengths of edges unchanged) with E * 1 unchanged. We get a new graph G * = (V * , E * ), such that V * = V and E * = E * 1 ∪ E * 2 . Then we also need to compute the new transition systems of G * . If e, g ∈ E * 1 and {e, g} ∈ T G (v) for some v ∈ V , then {e, g} ∈ T G * (v). If e, g ∈ E * 2 and {e, g} ∈ T G (v) for some v ∈ V , then {ḡ,ē} ∈ T G * (v). Here we useē,ḡ ∈ E * 2 to denote the reverse of e, g respectively.
Claim After reversing the edges of E * 2 , there is no dicycle in G * .
Proof (of claim) Suppose for contradiction that there is a dicycle C in G * . By Lemma 5.8, E(C) E * 1 , E(C) E * 2 . It follows that E(C) ∩ E * 1 = ∅ and E(C) ∩ E * 2 = ∅. Then by Lemma 5.9, E(C) should have been contracted in G , contradicting that C is a dicycle in G * .
We define a new digraph G as follows. Let W = E * 1 × E * 2 be its vertex set. For (e 1 , e 2 ), (e 1 , e 2 ) ∈ W , there is a directed edge from (e 1 , e 2 ) to (e 1 , e 2 ) if one of three cases hold. Then G s contains two T -compatible vertex-disjoint paths such that one path is from tail G ( f (e 1 )) to head G ( f (e 1 )) and the other path is from tail G ( f (e 2 )) to head G ( f (e 2 )).
In the third case above, we claim that v must belong to V 0 . Suppose for contradiction that v / ∈ V 0 . Clearly, v / ∈ {s 1 , s 2 , t 1 , t 2 }, as in must be both, head and tail of some edges. So there are two remaining cases. The first case is that v = u − for some u ∈ V (G). Then all outgoing edges of u − in G are parallel edges, that is, head G (e 2 ) = head G (e 1 ). Then e 1 and e 2 form a cycle in G * , contradicting that G * is acyclic. The second case is that v = u + for some u ∈ V (G). Then all ingoing edges of u + in G are parallel edges, that is, tail G (e 2 ) = tail G (e 1 ). Then e 1 and e 2 form a cycle in G * , contradicting that G * is acyclic. Thus v must belong to V 0 . Then we need to solve the vertex-disjoint version of 2-DSPP with transition restrictions in the acyclic graph G v ∪ {e 1 , e 1 , e 2 , e 2 }. The following lemma shows that we can do it in polynomial time. The algorithm is an adaption of the algorithm of finding two vertex-disjoint paths in DAG given by Perl and Shiloach [47]. Proof First we modify the graph G as follows. We create four vertices s 1 , s 2 , t 1 , t 2 and update V (G) as V (G) ← V (G) ∪ {s 1 , s 2 , t 1 , t 2 }. We create four edges s 1 s 1 , s 2 s 2 , t 1 t 1 , t 2 t 2 and update E(G) as E(G) ← E(G) ∪ {s 1 s 1 , s 2 s 2 , t 1 t 1 , t 2 t 2 }. Also, for i = 1, 2, we update T G (s i ) as For every vertex v ∈ V (G), define the level (v) as the length of a longest directed path in G starting from v. This can be computed by repeatedly removing a vertex of G. Then we create a graphG as follows. Let the vertex set ofG be V (G) = {(e 1 , e 2 ) | e 1 , e 2 ∈ E(G) and e 1 = e 2 }. For every (e 1 , e 2 ), (e 1 , e 2 ) ∈ V (G), create an edge from (e 1 , e 2 ) to (e 1 , e 2 ) if one of the following cases holds: (1) e 1 = e 1 , (head G (e 2 )) ≥ (head G (e 1 )), {e 2 , e 2 } ∈ T G (head G (e 2 )), head G (e 2 ) = tail G (e 1 ) and head G (e 2 ) = head G (e 1 ). (2) e 2 = e 2 , (head G (e 1 )) ≥ (head G (e 2 )), {e 1 , e 1 } ∈ T G (head G (e 1 )), head G (e 1 ) = tail G (e 2 ) and head G (e 1 ) = head G (e 2 ). (3) e 1 = e 1 = t 1 t 1 , (head G (e 2 )) < (t 1 ), {e 2 , e 2 } ∈ T G (head G (e 2 )). (4) e 2 = e 2 = t 2 t 2 , (head G (e 1 )) < (t 2 ), {e 1 , e 1 } ∈ T G (head G (e 1 )).
We claim that there are two T -compatible vertex-disjoint paths P 1 and P 2 in G such that P i is from s i to t i for i = 1, 2 if and only if there is a path P from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) inG. = t 2 t 2 . For any i ∈ {0, 1, . . . , p + 1}, j ∈ {0, 1, . . . , q + 1}, such that (i, j) = ( p + 1, q + 1), one of the following four cases must hold. As a result, there is a path P from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) inG. This finishes the proof for "only if" direction.
By the definition of edges ofG, we get that P 1 and P 2 are two T -compatible vertexdisjoint paths in G such that P i is from s i to t i for i = 1, 2. We can construct a graph G in O(|E| 3 ) time and find a path from (s 1 s 1 , s 2 s 2 ) to (t 1 t 1 , t 2 t 2 ) in O(|E| 3 ) time.
Thus the lemma holds.
By the results above, we can construct G in polynomial time. Now we show that we can solve the vertex-disjoint version of 2-DSPP with transition restrictions in G by finding a path in G from (s 1 s − 1 , t 2 t + 2 ) to (t + 1 t 1 , s − 2 s 2 ). Note that s − i , t + i ∈ V (G ) might be the endpoints of edges of E 0 for i = 1, 2. In this case, although we might contract the edges incident to s − i , t + i ∈ V (G ) and replace these vertices with new vertices, we slightly abuse s − i , t + i to denote the vertex adjacent to s i , t i respectively in G * for i = 1, 2 for the sake of simplicity.

Lemma 5.11
There is a directed path in G from (s 1 s − 1 , t 2 t + 2 ) to (t + 1 t 1 , s − 2 s 2 ) if and only if G has two vertex-disjoint T -compatible paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2.
Proof ("if" direction) Suppose that G has two vertex-disjoint T -compatible paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2. Recall that we contract If v ∈ V 0 , let G s be the subgraph of G consisting of all edges of G v together with f (e 1 ), f (e 1 ), f (e 2 ) and f (e 2 ). There are two T -compatible vertex-disjoint paths in G s , namely Q 1 from tail G ( f (e i 1 )) to head G ( f (e i+1 1 )) and Q 2 from tail G ( f (e i+1 2 )) to head G ( f (e i 2 )). Then P 1 ← P 1 · Q 1 \{ f (e i 1 ), f (e i+1 1 )}· f (e i+1 1 ) and P 2 ← f (e i+1 2 )· Q 2 \{ f (e i 2 ), f (e i+1 2 )}· P 2 . Otherwise, if v / ∈ V 0 , then P 1 ← P 1 · f (e i+1 1 ) and P 2 ← f (e i+1 2 ) · P 2 .
As a result, we construct two vertex-disjoint T -compatible paths P 1 and P 2 such that P i is from s i to t i and P i ⊆ E i for i = 1, 2. This finishes the proof for "only if" direction.
Since G contains O(|E| 3 ) edges, we can detect a path in G in polynomial time. Thus Lemma 5.11 shows that the vertex version of 2-DSPP with transition restrictions can be solved in polynomial time assuming that every cycle in the input graph has positive length.

Conclusions
We initiated exploring the parameterized complexity of finding paths, cycles, and walks in forbidden-transition and edge-colored graphs. Let us contemplate a few promising directions to take the exploration further.
First, a combinatorially interesting problem eluded us during this research: The NPhardness reduction of Szeider [49] for finding a (simple) path between two vertices of a forbidden-transition graph can be easily modified to prove that it is also NP-hard to find a (simple) compatible cycle in a forbidden-transition graph. In contrast, in edge-colored graphs finding any properly colored cycle is polynomial-time solvable [29,52]. But what about finding a long properly colored cycle? More precisely, given an edge-colored graph G and an integer k we ask whether G admits a simple properly colored cycle of length at least k. Is this problem fixed-parameter tractable when parameterized by k? As the notion of properly colored walks in edge-colored graphs generalizes walks in directed graphs, the problem in question is more general than finding a cycle of length at least k in a directed graph.
For the fundamental problem of finding compatible s-t paths we obtained essentially three positive results; each leads to natural follow-up questions. First, it is not hard to obtain fixed-parameter tractability when the length of the path is explicitly bounded by the parameter or implicitly so, as in the case of the treedepth and vertex-cover parameters. We have focused here only on some salient graph parameters, in particular, graph-width parameters. It may be useful to systematically explore the hierarchy of graph parameters and classify for which parameters the problem remains tractable [50].
Second, we obtained fixed-parameter tractability parameterized by the length of the detour over the shortest s-t path. A natural question is whether one can improve on this result by considering larger lower bounds on the length of the compatible s-t path. For example, we can obtain a larger lower bound by subdividing every edge of the input graph, replacing every vertex v by a set of length-two paths corresponding to the transitions of v, and then computing a shortest s-t path in the resulting graph.
Third, we obtained tractability for the treecut-width parameter. Other edge-cut based parameters are known [12,19] and it would be interesting to see which of them lead to fixed-parameter algorithms, or improved running times, for finding compatible s-t paths.
Next, it is interesting to deconstruct our hardness result, to obtain potential paths to tractability [21,38]. Our hardness result shows that finding compatible s-t paths is hard even on graphs that are close to trees in terms of vertex-deletion. However, the reduction works only if the size of the transition system and the number of vertices with forbidden transitions is not bounded by a parameter. It would hence be interesting to analyze the complexity with respect to these two parameters.
Finally, we observed in Sect. 5, that finding r disjoint shortest paths is polynomialtime solvable for r = 2 even if the paths are required to be compatible with a transition system. In the case of undirected graphs without forbidden transitions, this problem is polynomial-time solvable for each fixed r [8,42]. However, the problem is open for every r ≥ 3 in the case of directed graphs without forbidden transitions. This problem could be very interesting to generalize to forbidden-transition graphs, as it would be harder to design polynomial algorithms, but hardness would be easier to prove.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.