{'fraction_non_alphanumeric': 0.0538337044743791, 'fraction_numerical': 0.011000377225325205, 'mean_word_length': 3.6481900452488687, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 83, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Jungles, bundles, and fixed parameter tractability

We give a fixed-parameter tractable (FPT) approximation algorithm computing the path-width of a tournament, and more generally, of a semi-complete digraph. Based on this result, we prove that topological containment and rooted immersion problems are FPT on semi-complete digraphs.


Introduction
Graph Minors Theory of Robertson and Seymour [48] significantly reshaped the modern way of thinking about graphs. Apart from being a beautiful mathematical concept, the theory offers a number of fundamental algorithmic applications [46,47]. Arguably, the most fruitful of these is based on obstructions to admitting tree decompositions of small width. The structure of obstructions allows one to use the following WIN/WIN approach. If the treewidth of the input graph turns out to be small, it is possible to solve the problem efficiently, e.g., by applying dynamic programming. However, if the treewidth is large, we can find a sufficiently large obstruction, whose structure can be used either to immediately provide an answer, or to identify a vertex or an edge that is irrelevant to the solution, and hence can be safely removed from the graph. This approach is the corner stone of Robertson and Seymour seminal fixed-parameter tractable (FPT) algorithm checking, whether the input (undirected) graph G contains some fixed graph H as a minor [46]. As a consequence, various graph problems have been shown to have polynomial-time algorithms, some of which were previously not even known to be decidable [25].
Directed graphs. It is a very natural and important question, whether techniques and results of Graph Minors can be applied in the world of directed graphs or digraphs. In spite of many attempts, we are still very far from the right answer. Even to capture a good analogue for treewidth in digraphs is a non-trivial task and several notions like directed treewidth [38], DAG-width [11,44] or  can be found in the literature. However, none of them shares all the "nice" properties of undirected treewidth. In fact this claim can be formalized and proved; Ganian et al. argued that "any reasonable algorithmically useful and structurally nice digraph measure cannot be substantially different from the treewidth of the underlying undirected graph" [33].
The notion of graph minor is crucial in defining obstructions to small treewidth in an undirected graph. There are several ways to generalize this definition to digraphs and, as in case of treewidth, it is unclear which of them is the most natural. One approach is to consider topological embeddings or immersions. A graph H is a topological subgraph (or topological minor ) of graph G if H can be obtained from a subgraph of G by subdividing some of its edges. In other words, graph H can be embedded into graph G in such a way that edges of H correspond to vertex-disjoint paths in G. An immersion of a graph H into a graph G is defined like a topological embedding, except that edges of H correspond to edge-disjoint paths in G. Long standing open questions were to decide if a graph H can be topologically embedded (immersed) into G is fixed-parameter tractable, when parameterized by the size of H. Both questions were answered positively only very recently by Grohe,Kawarabayashi,Marx,and Wollan [36]. Unfortunately, the work of Grohe et al. cannot be extended to directed graphs. By the classical result of Fortune, Hopcroft, and Wyllie [29] the problem of testing whether a given digraph G contains H as a (directed) topological subgraph is NP-complete even for very simple digraphs H of constant size. Similar results can be easily obtained for immersions. Therefore, the most important two special cases of rooted topological embedding and immersions, namely Vertex (Edge) Disjoint Paths problems, were studied intensively on different classes of directed graphs. For example if we constrain the input digraphs to be acyclic, then both variants still remain NP-complete [24], but are polynomial-time solvable for every constant number of terminal pairs k [29], which was not the case in the general setting [29]. Slivkins showed that both problems are in fact W [1]-hard when parameterized by k [49], thus completing the picture of their parameterized complexity in this restricted case.
Tournaments form an interesting and mathematically rich subclass of digraphs. Many algorithmic problems were studied on tournaments, including problems strongly related to our work: Vertex (Edge) Disjoint Paths and Feedback Arc (Vertex) Set problems. In particular, Vertex (Edge) Disjoint Paths problems remain NP-complete on tournaments when k is a part of the input. However, they were known to be solvable in polynomial time for the case k = 2 on a superclass of tournaments called semi-complete graphs [8,10]. Different algorithmic aspects of the Feedback Arc (Vertex) Set problem are discussed in [2,3,4,12,14,42,45]. Recent work of Chudnovsky,Fradkin,Scott,and Seymour [15,16,17,30,31] drastically advanced the study of minor-related problems in tournaments. One of the main tools in this novel approach is the cutwidth of a digraph, which in tournament setting plays a similar role to the treewidth of undirected graphs. The main algorithmic advantage of cutwidth is that there is an FPT-approximation algorithm that in FPT time either finds a vertex ordering of width at most f (k), or constructs an obstruction for cutwidth k, for some function f [30]. By making use of cutwidth, Fradkin and Seymour gave an FPT algorithm for the Edge Disjoint Paths problem in tournaments. Similarly, for every digraph H of size k and an n-vertex tournament T , deciding if H has immersion in T can be done in time f (k)n 4 , for some function f [30].
The main limitation of cutwidth is that this parameter is not robust subject to even small changes in the digraph. For example, the cutwidth of an acyclic tournament with n vertices is zero, but adding just one vertex to this tournament can increase its cutwidth up to n/2 . In order to circumvent this limitation, Fradkin and Seymour in [31] obtained an obstruction theorem for pathwidth of a tournament, by showing that tournaments of large pathwidth always contain structures called jungles, and more refined objects called triples. Fradkin and Seymour also gave an algorithm that either computes a path decomposition of a tournament of width at most f (k), or outputs a triple of size k, for some function f . The running time of their algorithm is n m(k) for some function m; algorithms with such running times are often referred as XP algorithms, see the book of Flum and Grohe [26] for the formal definition of class XP. Pathwidth is a more general width parameter than cutwidth, so the Fradkin-Seymour obstruction theorem can be used to tackle more general problems. For example, this brings Fradkin and Seymour to an XP algorithm that for every digraph H of size k and n-vertex semi-complete digraph T , decides if H is topologically contained in T in time n m(k) , which is polynomial for fixed k [31]. The only obstacle for using pathwidth as a tool for obtaining FPT algorithms on tournaments was that there were no algorithms known constructing or approximating the pathwidth of a tournament in FPT time.
Our results. We eliminate the existing limitations of pathwidth and show that it is possible in FPT time either to construct a path decomposition of "small" width, or to find a "large" triple, which topologically contains all "small" digraphs and is an obstruction for pathwidth k. Our algorithm is based on structural theorems of Fradkin and Seymour [31] but requires several new ideas. More precisely, we prove the following theorem. (In Section 2 we define semi-complete digraphs -a superclass of tournaments, pathwidth, jungles and triples) Theorem 1. There is an algorithm that for a given semi-complete graph T = (V, E) and an integer k, in time 2 O(k log k) |V | 3 log |V | outputs (1) either a path decomposition W of width at most 4k 2 + 7k, (2) or a k-jungle J .
Fradkin and Seymour prove that if a semi-complete digraph contains a f (k)-jungle, then it contains also a k-triple, in which every digraph of size k can be topologically embedded. From a close examination of their proof one can extract an algorithm with running time O(|V | 3 log |V |). Thus, if the digraph has large pathwidth, then every small enough digraph can be topologically embedded into it. On the other hand, it easy to show that the cliquewidth of a semi-complete digraph is always at most its pathwidth plus 2. Since topological minor containment problem is expressible in MSO 1 , the results of Courcelle, Makowsky and Rotics [20] immediately give an FPT algorithm parameterized by the width of the obtained path decomposition and the size of the embedded digraph. This implies that Topological containment (we give precise definition of the parameterized problem Topological containment in Section 2) in semi-complete digraphs is FPT, which substantially improves the algorithm of Fradkin and Seymour [31]. We remark that it is also possible to construct an explicit dynamic programming algorithm working on path decomposition, thus circumventing the usage of tools from logic.

Theorem 2.
There exists an algorithm, which given a digraph H and a semi-complete digraph T = (V, E), checks whether H is topologically contained in T in time g(|H|)|V | 3 log |V | for some elementary function g.
Next application of Theorem 1 shows that the rooted immersion, which is a common generalization of immersion and the Edge Disjoint Paths problem, is FPT on semi-complete digraphs.

Theorem 3.
There exists an algorithm, which given a rooted digraph (H; v 1 , v 2 , . . . , v t ) and a semi-complete rooted digraph (T ; w 1 , w 2 , . . . , w t ), checks whether H can be immersed into T while preserving roots in time g(|H|)|V (T )| 4 log |V (T )| for some elementary function g. Fradkin and Seymour in [30], where they showed that its close relative, rooted infusion, is FPT on semi-complete digraphs. As rooted infusion generalizes the Edge Disjoint Paths problem as well, the complexity of k-Edge Disjoint Paths was already established by Fradkin and Seymour; however, the approach presented in [30] is much more complicated than ours. Our proof is based on a non-trivial application of the irrelevant vertex technique, which allows to identify a vertex in semi-complete digraphs of large pathwidth, whose removal does change the answer to the problem. It is possible to use the ideas of Ganian et al. [34] for the Edge Disjoint Paths problem to prove that Rooted Immersion is expressible in MSO 1 , which in combination with the irrelevant vertex procedure and Theorem 1 shows that Rooted Immersion is FPT on semi-complete digraphs. Unfortunately, the formula obtained in this way has unbounded quantifier alternation, so a direct application of the framework of Courcelle, Makowsky and Rotics [20] gives a non-elementary dependence on |H|, i.e., the tower of height depending on |H| in the exponent of the bound on the running time. To overcome this we give an explicit dynamic programming algorithm.

The complexity of this problem was left open by
Finally, we observe that our framework can be used to prove meta-theorems of more general nature. Let Π be a class of digraphs and denote by Π + kv the class of digraphs, from which one can delete at most k vertices to obtain a member of Π. We study the following problem: Parameter: k Input: Digraph D and integer k Question: Is there S ⊆ V (D), |S| ≤ k, such that D \ S ∈ Π?
We are interested in classes Π which are closed under immersion. For example the class of acyclic digraphs, or digraphs having cutwidth at most c, where c is some constant, are of this type. In particular, the parameterized Feedback Vertex Set in directed graphs is equivalent to Π+kv Recognition for Π being the class of acyclic digraphs. Chudnovsky and Seymour [17] showed that immersion order on semi-complete digraphs is a well-quasi-order. Based on this result and Theorem 1, we are able to prove the following meta-theorem. Note that it seems difficult to obtain the results of this flavor using cutwidth, as cutwidth can decrease dramatically even when one vertex is deleted from the digraph.
Theorem 4. Let Π be an immersion-closed class of semi-complete digraphs. Then Π + kv Recognition is FPT on semi-complete digraphs.
To complete the picture of the presented framework, we investigate the possibilities of proving logical meta-theorems yielding FPT algorithms working on path decomposition of semicomplete digraphs. As pathwidth resembles treewidth in the undirected case, one could conjecture that, similarly to Courcelle's Lemma, MSO 2 model checking should be also fixed-parameter tractable, when the pathwidth of the given semi-complete digraph and length of the formula are parameters. The following result shows that this is unfortunately not true.

Theorem 5.
There exists a constant-size MSO 2 formula ψ, such that checking whether ψ is true in a semi-complete digraph of constant cutwidth and pathwidth is NP-hard.
Outline. The remaining part of the paper is organized as follows. In Section 2 we introduce all the necessary notions and recall various tools that will be used. Section 3 contains descriptions of the proofs of Theorems 1, 2, 3 and 4. Finally, in Section 4 we gather conclusions and deliberate on new challenges arising from the current work. The proof of Theorem 5 has been deferred to Appendix D, which contains a detailed description of tools from logic applicable in our setting.

Preliminaries
Let G = (V, E) be a finite digraph. Digraphs can have loops and multiple edges. We refer to the book of Bang-Jensen and Gutin [9] for an introduction to directed graphs. We use V (G) and E(G) to represent the vertex set and arc set of G, respectively. By the size of G we denote ) of a vertex v is the number of its inneighbours (out-neighbours). We denote by N − (v) and by N + (v) the set of all in-neighbours and out-neighbours of v correspondingly.
A digraph is simple if it has no loops, and for every pair of distinct vertices u, v there is at most one arc (u, v). A digraph is semi-complete if it is simple and for every pair of distinct vertices u, v there is at least one arc with endpoints u, v. A digraph is a tournament if it is simple and for every pair of distinct vertices u, v there is exactly one arc with endpoints u, v.
Topological containment and immersions. Let H, G be digraphs. We say that mapping η : if the following conditions are satisfied: • for every edge (u, v) ∈ E(H), η ((u, v)) is a directed path leading from η(u) to η(v); • for every loop (u, u) ∈ E(H), η ((u, u)) is a directed cycle passing through η(u).
By imposing further conditions on the model we obtain various notions of containment for digraphs. If we require that η is surjective on V (H) and the paths in η(E(H)) are internally vertex-disjoint, we obtain the notion of topological containment; in this case we say that η is an expansion of H in G. If we relax the condition of paths being internally vertex-disjoint to being edge-disjoint, we arrive at the notion of immersion; then η is an immersion 1 of H into G.
In our setting we are given digraph H (with possible loops and multiple edges) and a semicomplete digraph T . We ask whether H is topologically contained (immersible) in T . Observe that without changing the answer for these questions we can subdivide once every loop in H. Thus we may assume that H does not contain any loops; though, it may have multiple edges.
We say that (G; v 1 , . . . , v h ) is a rooted digraph if G is digraph and v 1 , . . . , v h are distinct vertices of V (G). The notion of immersion can be generalized to rooted graphs. Immersion η is an immersion from rooted digraph H = (H; u 1 , . . . , u h . . . , h}. Such an immersion is called an H-immersion or a rooted immersion.
We study the following parameterized topological containment and immersion problems.

Topological containment
Parameter: |H| Input: Digraphs H and G Question: Is there expansion of H in G?

H-immersion (Rooted Immersion)
Parameter: |H| Input: Rooted digraphs H and G Question: Is there H-immersion of H in G?
The set A ∩ B is the cut corresponding to the separation (A, B). Two separations (A, B) and (C, D) cross unless one of the following holds: A set of separations is cross-free if no two of its members cross.

Lemma 1.
Let G be a digraph and t ≥ 0 be a integer. Let S be a cross-free set of separations with |S| = t. Then the members of S can be ordered ( Definition 2. Given a digraph G = (V, E), a sequence W = (W 1 , . . . , W r ) of subsets of V is a path decomposition of G if the following conditions are satisfied: We call W 1 , . . . , W r the bags of the path decomposition. The width of a path decomposition is equal to max 1≤i≤r (|W i | − 1); the pathwidth of G is the minimum width over all path decompositions of G.
Jungles and triples. For a semi-complete digraph T , a set Z ⊆ V (T ) is called a k-jungle if |Z| = k and for every x, y ∈ Z there does not exist a separation (A, B) of order smaller than k that separates y from x, i.e., such that x ∈ A \ B and y ∈ B \ A. A triple of disjoint subsets (A, B, C) is called a k-triple if |A| = |B| = |C| = k and there exist orderings (a 1 , . . . , a k ), (b 1 , . . . , b k ), (c 1 , . . . , c k ) of A, B, C, respectively, such that for all indices 1 ≤ i, j ≤ k we have (a i , b j ), (b i , c j ) ∈ E(G) and for each index 1 ≤ i ≤ k we have (c i , a i ) ∈ E(G). The following result is an algorithmic version of the result of Fradkin and Seymour [31, (2.6)]. The proof closely follows the lines of their argumentation; however, for the sake of completeness we include it in Appendix A.

Lemma 2.
There exists an elementary function f , such that for every k ≥ 1 and every semicomplete graph T given together with its f (k)-jungle, it is possible to construct a k-triple in T in time O(|V (T )| 3 log |V (T )|).
It is easy to check that both a k-triple and a k-jungle are obstacles to admitting a path decomposition of width less than k − 1; there must be a bag containing the whole part B or the whole jungle, respectively. The following simple observation is also due to Fradkin and Seymour [31].

Lemma 3.
Every digraph H is topologically contained in a |H|-triple.
Tools from logic. We gather a detailed discussion on the applicability of tools from logic in our setting in Appendix D. Essentially, we observe that as on semi-complete graphs cliquewidth can be bounded by a function of pathwidth, and model checking of formulas of the logic MSO 1 can be done by a fixed-parameter algorithm, parameterized by the length of the formula and cliquewidth, we get the following powerful meta-tool for constructing algorithms on path decomposition. For appropriate definitions we invite an interested reader to Appendices C and D.

Theorem 6.
There exist an algorithm with running time f (||ϕ||, p)|V (T )| 2 that given an MSO 1 formula ϕ checks whether ϕ is satisfied in a semi-complete digraph T , given together with a path decomposition of width p.

Approximation of pathwidth: proof of Theorem 1
In this section we give an approximation algorithm computing the pathwidth of a semi-complete digraph. As the algorithm makes use of the same concepts as the technique of Fradkin and Seymour [31], we need to introduce the essential terminology.
Let (A, B), (C, D) be separations of G that do not cross and suppose they have orders i, j, respectively. Without loss of generality, suppose that A ⊆ C and D ⊆ B. We say that (A, B) and (C, The notion of a bundle is crucial for computing the pathwidth of a semi-complete digraph.

Definition 3 (Bundle).
For an integer k > 0, a bundle in G of order k is a cross-free set B of separations of G, each of order < k, such that (i) no two members of B are k-close; (ii) if (A, B) is a separation of G of order i < k, then one of the following holds: We say that U is (k, )-separable if there exists an -separator of U of order at most k.
The following proposition implicitly follows from the proof of (2.11) in [31].
Lemma 4. Let B be a bundle of order k and let (A 1 , B 1 ), (A 2 , B 2 ), . . . , (A m , B m ) be the members of B ordered such that A 1 ⊆ · · · ⊆ A m and B m ⊆ · · · ⊆ B 1 . If for some 1 ≤ j ≤ m, We are now ready to prove Theorem 1.
Proof of Theorem 1. The first steps of ours are similar to the approach of Fradkin and Seymour [31]; however, we need to use new techniques to obtain a substantially better running time.
If the width of W is at most 4k 2 + 7k, then the algorithm outputs W and terminates. Otherwise, there is such an index j, for which |A j+1 ∩ B j | > 4k 2 + 7k. As Therefore, to prove the theorem, it is sufficient to show how to (a) Construct a bundle of order k in time 2 O(k log k) |V | 3 log |V |, and (b) Construct in time O(|W | 2 ) a k-jungle from a set W of cardinality at least 5k+4 , providing it is not (k, )-separable.
(a) Construction of a bundle. We will inductively construct a sequence of more and more refined cross-free families of separations B 1 , B 2 , . . . , B k , such that following conditions are satisfied: • B i is a cross-free family of separations of order < i; • no two separations in B i are k-close; • for every i ≤ k, every separation of T of order < i either belongs to B i , crosses some separation from B i or is k-close to some separation from B i .
These conditions imply that B k is a bundle of order k. Note that families B i are not necessarily bundles of order i for i < k, as the closeness conditions refer to the value of k instead of i. We begin with constructing the family B 1 consisting of separations of order 0. In O(|V | 2 ) time we partition T into strongly connected components; as T is a tournament, the acyclic digraph of strongly connected components is a linear order. Let F 1 , F 2 , . . . , F h be these components, ordered with respect to this linear order. As B 1 we take the family of separations of order 0 defined as follows: It is easy to check that conditions imposed on B 1 are satisfied. Now we present an algorithm that given family B i constructs family B i+1 . We take B i+1 := B i and greedily incorporate new separations of order i into B i+1 , such that every new separation does not cross older ones and is not k-close to any of them. Having obtained such a maximal family B i+1 , i.e., one, into which no new separation can be incorporated, we conclude that all the conditions imposed on B i+1 are satisfied.
be the separations at some step of the construction of B i+1 ordered by an ordering obtained from Lemma 1. Note that (A 1 , B 1 ) = (∅, V (T )) and (A h , B h ) = (V (T ), ∅); therefore, every new separation has to be inserted between two consecutive separations that are already in B i+1 . We try to insert the new separation between (A j , B j ) and (A j+1 , B j+1 ) for every j ∈ {1, 2, . . . , h − 1}. If we do not succeed for any j, we conclude that B i+1 is already maximal.
Consider inserting a new separation (C, D) between (A j , B j ) and (A j+1 , B j+1 ). We have the following simple claim: The proof of Claim 1 uses standard triangle inequality properties of set operations, and can be found in Appendix A. Hence, we can only check that the new separation is not k-close In this semi-complete digraph we have two sets of terminals: We need to determine, whether there exists a separation (C , D ) of S of order i that separates X from Y , is not kclose to the separation (X, V (S)) nor to the separation (V (S), Y ), and is distinct from both of them. Every such a separation (C , D ) corresponds to an objective separation (C, D) = (C ∪ A j , D ∪ B j+1 ) and vice versa: every objective separation (C, D) induces such a separation (C , D ) = (C ∩ V (S), D ∩ V (S)) in S. Therefore, we need to solve the following problem in the

Semi-complete Digraph Balanced Cut
Parameter We show an algorithm that solves Semi-complete Digraph Balanced Cut in time 2 O(min(a+c,b) log(a+b+c)) |V (S)| 2 log |V (S)|. Before we proceed to its presentation, let us shortly discuss why it will finish the proof of Theorem 1. We only need to show that the number of applications of this subroutine is bounded by O(k|V (T )|), as for each call we have |V (S)| ≤ |V (T )| and O(min(a + c, b) log(a + b + c)) = O(k log k). Note that the number of calls with a positive result, i.e., those that finished with finding a feasible separation, is bounded by O(|V (T )|) for the whole run of the algorithm, as each such result implies incorporating one new separation to the constructed path decomposition. Moreover, for every considered i the number of calls with negative results obtained while considering i is bounded by the size of the bundle after this step, thus also by O(|V (T )|). It follows that the total number of calls is bounded by O(k|V (T )|) and we are done.
The algorithm for Semi-complete Digraph Balanced Cut is based on the technique of color coding, a classical tool in parameterized complexity introduced by Alon et al. [5]. Although the intuition behind color coding is probabilistic, it is well-known that almost all algorithms designed using this approach can be derandomized using the technique of splitters of Naor et al. [43]. We find it more convenient to present our algorithm already in the derandomized version. We will use the following folklore abstraction of derandomization of random coloring; for the sake of completeness, the proof can be found in Appendix A.

Lemma 5.
There exists an algorithm, which given integers p, q and universe U , in time 2 O(min(p,q) log(p+q)) |U | log |U | returns a family F of subsets of U of size 2 O(min(p,q) log(p+q)) log |U | with the following property: for every subsets A, B ⊆ U , such that A ∩ B = ∅, |A| ≤ p and |B| ≤ q, there exists a set R ∈ F such that A ⊆ R and B ∩ R = ∅.
First, using Lemma 5 in time 2 O(min(a+c,b) log(a+b+c)) |V (S)| log |V (S)| we generate a family F for universe U = V (S) and constants p = a+c, q = b; note that |F| ≤ 2 O(min(a+c,b) log(a+b+c)) log |V (S)|. Properties of F ensure that for every separation (C, D) that satisfies properties given in the problem statement, there exists a set R ∈ F such that | In such a situation we say that R is compatible with separation (C, D). We iterate through the family F, for each R ∈ F trying to find a separation that is compatible with it; by Lemma 5, for at least one choice we are able to find a feasible separation.
Consider the subdigraph S R = S[R]. In O(|V (S)| 2 ) time partition S R into strongly connected components. As S R is semi-complete, they can be naturally arranged in a linear order, such that the arcs between different components are directed only to the one lower in the order. Let us denote this order of the components by ( , a prefix of the order is entirely contained in one side of the separation, and the corresponding suffix is entirely contained in the second side. Let h 1 be the smallest index such that Clearly, h 1 ≤ h as otherwise either there would be less than a vertices in the intersection of R and C \ D, or there would be a vertex of where vertices from R have infinite capacity, while vertices from V (S)\R have unit capacities. This can be done in O(b|V (S)| 2 ) time using the classical Ford-Fulkerson algorithm: note that once b + 1 paths are found, we may terminate further computation, as no cut of small enough size can be found.
(b) Constructing a jungle. Assume we have a set W , such that |W | ≥ 5k + 4 and W is not (k, )-separable. Our construction mimics the proof of (2.8) Note that for any semi-complete digraph and any integer d, the number of vertices of outdegree at most d is bounded by 2d + 1, as otherwise already in the subdigraph induced by them there would be a vertex of higher outdegree. The same holds for indegrees. Hence, we infer that |Z| ≥ |W | − (2(k + ) − 1) − (2(k + ) − 1) ≥ k. Take any x, y ∈ Z. For the sake of contradiction, assume that there is a separation (A, B) of order less than k that separates x from y.
However, this means that either x or y has in-degree or out-degree in S bounded by k + − 1, a contradiction with x, y ∈ Z. Therefore, every subset of Z of cardinality k is the desired k-jungle J .

Irrelevant vertex procedure for rooted immersion
In this section we show the crucial ingredient needed for the application of the framework to Theorem 3. As we consider the rooted version of the problem, in the case of finding a large obstacle we cannot immediately provide an answer. Instead, we make use of the so-called irrelevant vertex technique: we identify a vertex in the obstacle that can be safely removed from the digraph. In Section 3.3 we show how the following result can be used in the proof of Theorem 3.
In our proof p(x) = 80x 2 + 80x + 5. The proof is quite long and technical, so here we present only a brief, intuitive sketch. The full, formal version can be found in Appendix E.
Recall that in the triple (A, B, C) we have arcs from every vertex of A to every vertex of B, from every vertex of B to every vertex of C, and there exists a matching between C and A that consists of arcs directed from C to A. Let us assume that I is a YES instance and let η be the corresponding rooted immersion of H such that Q = η(E(H)), the family of paths between corresponding images of vertices of H, has minimum total sum of lengths. To ease the presentation, we assume that none of vertices of the triple is in η(V (H)). The goal is to find a vertex x in the part B, such that all the paths going through x can be rerouted around -thus we prove that if there exists some solution, then there exists also a solution that does not use x. We first observe some structural properties of the family Q that follow from its minimality. The intuition is that if a path from Q visits one of the parts A, B, C multiple times, then one can use some unused parts of the triple to create a shortcut between the first and the last visit. All in all, one can show that at most 4k vertices from B are visited by some path from Q, and at most O(k 2 ) arcs of the matching between C and A have an endpoint visited by some path of Q. Thus, by choosing the size of the triple to be sufficiently large, one may assume that we are given an arbitrary large reservoir of free vertices from B and free arcs of the matching between C and A that can be used for rerouting.
Consider vertex x ∈ B. The goal is to modify the family Q to Q so that (i) if a path enters x, then it enters x from A; (ii) if a path leaves x, then it leaves x to C. Once both properties are satisfied, we can rerout all the paths going through x to some other free vertex from B. Of course, this can be not possible for all vertices x. We find a vertex for which this is possible in two phases. First, we find a sufficiently large set X ⊆ B, such that for each x ∈ X one can find an intermediate family Q for which just (i) is satisfied. Second, inside X we find a single vertex x, for which Q can be further modified to Q satisfying both (i) and (ii). Note that we have to keep track of the number of free vertices and free edges used during the first phase so that the second phase has still enough space for reroutings. We now explain only how the first phase can be performed -the second phase follows the same scheme.
For each b ∈ B, we partition the inneighbors of b outside A into two sets. One set, denoted R b , contains these inneighbors, which have a sufficiently large number of outneighbors in B. We observe that every path entering b from R b can be easily rerouted, because each vertex of R b must have a large number of free outneighbors in B, so we can redirect the path via a free outneighbor in B and around the whole triple back to b, using one free arc of the matching between C and A. The second set, denoted G b , contains vertices that have small number of outneighbors in B and are hence problematic. However, if sufficiently many vertices b have empty G b , we can already output these vertices as a feasible X.
Otherwise, we consider the vertices with nonempty G b and we know that we have a large number of them. We define an auxiliary digraph S on the set of vertices b ∈ B with nonempty Here comes the main trick of the proof: the fact that T is semi-complete implies that so do S. Now consider a vertex b ∈ B with high outdegree in S. We show how a path entering b from v ∈ G b can be rerouted so that it enters b from A. As b has large outdegree in S, for many b ∈ B which are still free we can access some v ∈ G b either by staying in v (if v ∈ G b ) or using one arc. If v = v for some b , we can follow the same strategy as for the sets R b . Otherwise, we need to check that some of the arcs accessing vertices v are not yet used by other paths; this can be problematic as vertices v are not necessarily distinct. However, we know that each of them belongs to some G b , so they can appear only in limited number of copies as they have only limited number of outneighbors in B. Hence, we can distinguish sufficiently many pairwise distinct ones to be sure that one of the arcs accessing them is not yet used. Therefore, we can replace usage of the arc (v, b) with first accessing some other G b , then the free vertex b , and then moving around the triple using a free arc of the matching between C and A (see Figure 1 in Appendix E for an illustration). As S is semi-complete and sufficiently large, there exists a sufficiently large number of vertices b with sufficiently large outdegree in S, from which the set X can be formed.

Sketches of proofs of Theorems 2, 3 and 4
In this Section we sketch how Theorems 2, 3 and 4 follow from an application of the WIN/WIN approach. The proofs are essentially arranging already known pieces together, so we just discuss the main ideas. Fully formal descriptions can be found in Appendix B.
Theorem 2 follows almost directly from Theorems 1, 6 and Lemmas 2, 3. We first run approximation of pathwidth. If pathwidth is too large, we are guaranteed that the digraph contains a sufficiently large triple, which topologically contains every digraph of given size. Hence, we may provide a positive answer. Otherwise, we have a path decomposition of small width, on which we can run the algorithm given by Theorem 6. One just needs to observe that containing H topologically can be expressed in MSO 1 : the formula existentially quantifies over images of vertices of H, and then checks existence of disjoint paths as disjoint subsets of vertices in which endpoints cannot by separated by separation of order 0. We remark that the quantifier alternation of this formula is constant, so the obtained running time dependence on the size of H is elementary.
For Theorems 3 and 4 it will be convenient to use the following surprising result of Ganian et al. [34]: for every there exists an MSO 1 formula π (s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t ) that for a digraph with distinguished vertices s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t (some of which are possibly equal) asserts whether there exists a family of edge-disjoint paths P 1 , P 2 , . . . , P such that P i begins in s i and ends in t i for i = 1, 2, . . . , . For Theorem 3 we proceed similarly as before. After approximating pathwidth, we either obtain a large triple, in which using Theorem 6 we can find an irrelevant vertex that can be safely removed, or obtain a path decomposition of small width, on which we can run algorithm given by Theorem 6 for an appropriate adaptation of formula π |E(H)| . We obtain an additional O(|V (T )|) overhead in the running time, as we may O(|V (T )|) time run the approximation algorithm and remove one vertex. Unfortunately, the quantifier alternation of formula π depends on , so we do not obtain elementary dependence of the running time on the size of immersed graph. However, one can explicitly construct a dynamic program on path decomposition with elementary dependence. We provide such an algorithm in Appendix F. Using the same technique one can also obtain a dynamic program for topological containment with similar running time bounds; we omit the details. We remark that application of the formulas π in the context of immersion in semi-complete digraphs has been already observed by Ganian et al. [34].
Theorem 4 follows from combining this approach with the result of Chudnovsky and Seymour that immersion order on semi-complete tournaments is a well-quasi-order [17]. By [17], class Π can be characterized by a finite set of forbidden immersions {H 1 , H 2 , . . . , H r }. By a simple adaptation of formulas π , for each H i we can construct an MSO 1 formula with one free monadic variable X that asserts that after removing X the graph does not admit H i as an immersion. By taking conjunction of these formulas and quantifying X existentially we obtain an MSO 1 formula that asserts belonging to Π + kv. In order to finish the proof it suffices to observe that the digraphs from the class Π + kv have bounded pathwidth: a digraph with large pathwidth contains a big triple, which after removing at most k vertices still contains every sufficiently small graph as an immersion. We run the algorithm from Theorem 1. If we obtain a large obstacle, we provide a negative answer; otherwise, we run the algorithm given by Theorem 6.

Conclusions and open problems
In this paper we showed that Topological containment and H-immersion are FPT on semi-complete graphs. A natural common generalization of Topological containment and k-Vertex Disjoint Paths is the rooted version of Topological containment, where specified vertices of H should be mapped into specified vertices of G. The obvious next step of research would be to try to extend the results to rooted topological containment. Chudnovsky, Scott and Seymour in [16] proved that k-Vertex Disjoint Paths is in class XP on semicomplete, i.e., solvable in polynomial time for fixed k. This also implies that the rooted version of topological containment is in XP on semi-complete graphs.
Unfortunately, our approach used for rooted immersion does not apply to this problem. Dynamic programming on path decomposition works fine but the problem is with the irrelevant vertex arguments. Even for k = 2 there exist tournaments that contain arbitrarily large triples, but in which every vertex is relevant; we provide such an example in Appendix G. This suggests that a possible way to obtaining an FPT algorithm for Vertex Disjoint Paths problem requires another width parameter admitting more powerful obstacles.
The next step in the proof of Fradkin and Seymour is to partition the set X into parts X 1 and X 2 of size 6s each such that X 1 is complete to X 2 , i.e., for each x 1 ∈ X 1 and x 2 ∈ X 2 we have (x 1 , x 2 ) ∈ E(T ). Such a partition of the vertex set of the transitive semi-complete digraph can be easily found in time O(|X| 2 ). Because X is a 12s-jungle in T , there are at least 6s internally vertex-disjoint paths from X 2 to X 1 in T . Let R be a minimal induced subdigraph of T such that X ⊆ V (R) and there are 6s vertex-disjoint paths from X 2 to X 1 in R. Such a minimal subgraph R can be found in time O(|V (T )| 3 log |V (T )|) by repeatedly removing vertices v ∈ V (T )\X if there are 6s vertex-disjoint paths from X 2 to X 1 in V (T )\{v}. As the subroutine for finding the paths we use the classical Ford-Fulkerson algorithm, where we finish the computation after finding 6s paths. Hence, the running time is O(s|V (T )| 2 ). As we make at most |V (T )| tests, and s = O(log |V (T )|), the claimed bound on the runtime follows.
Let P 1 , P 2 , . . . , P 6s be vertex-disjoint paths from X 2 to X 1 in R. Fradkin and Seymour proved that the set of vertices Q formed by the first two and the last two vertices of these 6s paths contains a k-triple. Thus, by checking every triple of subsets of Q of size k in time polynomial in k, we can find a k-triple. This step takes time O 24s Proof of Claim 1 from the proof of Theorem 1. We are to prove that if the new separation (C, D) inserted between (A j , B j ) and (A j+1 , B j+1 ) is not k-close to (A j , B j ) nor to (A j+1 , B j+1 ), then it is not k-close to any separation (A r , B r ) ∈ B i+1 . By symmetry we assume that r < j. Let us recall that A r ⊆ A j ⊆ C ⊆ A j+1 and B r ⊇ B j ⊇ D ⊇ B j+1 . As no separations already inside B i+1 are k-close, we have that This proves that (A r , B r ) and (C, D) are not k-close.
Proof of Lemma 5. Without loss of generality we may assume that p ≤ q, as we can always replace every set in the constructed family with its complement, thus switching roles of p and q. An (n, r, r )-splitter S is a family of functions from a universe U of size n to the set {1, 2, . . . , r } such that for every X ⊆ U , |X| = r, there exists f ∈ S that is injective on X. Naor et al. [43] gave an explicit construction of (n, r, r 2 )-splitter of size O(r 6 log r log n) in time O(poly(r) · n log n). Using the algorithm of Naor et al. we construct a (n, z, z 2 )-splitter S on U , where z = min(p + q, n). Then, for every f ∈ S and every Z ⊆ {1, 2, . . . , z 2 }, |Z| = p, we add to the constructed family F the set f −1 (Z). Assume now that we have A, B ⊆ U such that |A| ≤ p and |B| ≤ q. Obtain A and B by adding arbitrary elements of U \ (A ∪ B) to A and B so that |A | + |B | = z. By definition of the splitter, there exists f ∈ S that is injective on A ∪ B . To finish the proof one needs to observe that if we take R = f −1 (f (A )), then A ⊆ R and B ∩ R = ∅. The bounds on the time complexity of the algorithm and on the size of F follow from the bounds given by Naor et al. and from the fact that the number of subsets of {1, 2, . . . , z 2 } of size p is bounded by 2 O(p log z) ≤ 2 O(p log(p+q)) .

B Full proofs of Theorems 2, 3 and 4
Proof of Theorem 2. Let f be the function given by Lemma 2 and denote k = f (|H|). We first apply the algorithm from Theorem 1, which in 2 O(k log k) |V | 3 log |V | time finds either a k-jungle in T , or returns a path decomposition of width at most 4k 2 + 7k. In the first case, by Lemma 2 we know that T contains a |H|-triple. Lemma 3 asserts that we may safely provide a positive answer. Otherwise, we can observe that we can easily construct an MSO 1 formula ϕ H that checks, whether H can is topologically contained in T . First, we existentially quantify over the images of vertices of H. Then, for every (u, v) ∈ E(H) we quantify existence of a set X (u,v) , such that all the sets X (u,v) are vertex disjoint and X (u,v) ∪ {η(u), η(v)} does not admit a separation of order 0 that separates η(v) from η(u). This asserts existence of required paths between vertices. We can conclude the proof by applying Theorem 6 to formula ϕ H and semi-complete digraph T . In order to show that the obtained running time is elementary, one can to observe that the formula ϕ H has constant quantifier alternation, so the dependence on ||ϕ H || and width of the decomposition of the running time of the algorithm given by Theorem 6 is elementary. Alternatively, one can construct the dynamic program on path decomposition by hand in a similar manner as the dynamic program for rooted immersion, given in Appendix F.
Proof of Theorem 3. The algorithm performs at most |V (T )| iterations. In each iteration we either delete one vertex from the graph so that the answer does not change, or resolve the problem completely. The complexity of each step is h(|H|)|V (T )| 3 log |V (T )|, which gives a h(|H|)|V (T )| 4 log |V (T )| bound on the total running time.
In each step we run algorithm from Theorem 1 for k = f (p(|H|)) and semi-complete digraph T \{v 1 , v 2 , . . . , v t }, which in time 2 O(k log k) |V (T )| 3 log |V (T )| either outputs a path decomposition of T \{v 1 , v 2 , . . . , v t } of width at most O(k 2 ), or a k-jungle in T \{v 1 , v 2 , . . . , v t }. If we find a jungle using Theorem 2 in O(|V (T )| 3 log |V (T )|) time we can find a p(k)-triple in T \ {v 1 , v 2 , . . . , v t } and, by further usage of Theorem 6, an irrelevant vertex in it. Theorem 6 ensures that removal of this very vertex yields an equivalent instance.
However, if we obtain a decomposition, we can include all the excluded roots into every bag (note that there are at most |V (H)| of them) to obtain a decomposition of T . Then we may proceed in two ways. Firstly, let us recall the result of Ganian et al. [34], that for every there exists an MSO 1 formula π (s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t ) that for a digraph with distinguished vertices s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t (some of which are possibly equal) asserts whether there exists a family of edge-disjoint paths P 1 , P 2 , . . . , P such that P i begins in s i and ends in t i , for i = 1, 2, . . . , . We take formula π |E(H)| (s 1 , s 2 , . . . , s |E(H)| , t 1 , t 2 , . . . , t |E(H)| ), additionally quantify existentially images of vertices of H that are not roots, and replace variables s i , t i with corresponding roots or quantified images. Thus we obtain a new formula ϕ H that asserts that H is a rooted immersion of T. We may now use Theorem 6 to obtain the algorithm. Unfortunately, as the formula constructed by Ganian et al. [34] has quantifier alternation depending on |H|, the guarantees on the running time obtained in this manner are non-elementary. However, it is possible to construct a dynamic program on path decomposition by hand, which has elementary dependence on the width and |H|. We provide the details in Appendix F.

Proof of Theorem 4. As Π is immersion-closed, by the result of Chudnovsky and Seymour [17]
that immersion order on semi-complete tournaments is a well-quasi-order, we infer that Π can be characterized by admitting none of a family of semi-complete digraphs {H 1 , H 2 , . . . , H r } as an immersion, where r = r(Π) depends only on the class Π. Let us recall the result of Ganian et al. [34], that for every there exists an MSO 1 formula π (s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t ) that for a digraph with distinguished vertices s 1 , s 2 , . . . , s , t 1 , t 2 , . . . , t (some of which are possibly equal) asserts whether there exists a family of edge-disjoint paths P 1 , P 2 , . . . , P such that P i begins in s i and ends in t i for i = 1, 2, . . . , . For every i ∈ {1, 2, . . . , r} we construct an MSO 1 formula ϕ i (X) that is true if digraph G \ X contains H i as an immersion: we simply quantify existentially over the images of vertices of H i , use the appropriate formula π |E(H)| for quantified variables to express existence of paths, and at the end relativize the whole formula to the subdigraph induced by V (T ) \ X. Hence, if we denote by ψ k (X) the assertion that |X| ≤ k (easily expressible in the first order logic by a formula, whose length depends on k), the formula ϕ = ∃ X ψ k (X) ∧ r i=1 ¬ϕ i (X) is true exactly in semi-complete digraphs, from which one can delete at most k vertices in order to obtain a semi-complete digraphs belonging to Π.
Observe that class Π has bounded pathwidth, as by Theorem 2 and Lemma 2, a semicomplete digraph of large enough pathwidth contains a sufficiently large triple, in which one of the graph H i is topologically contained, so also immersed. It follows that if pathwidth of Π is bounded by c Π , then pathwidth of Π + kv is bounded by c Π + k. Therefore, we can apply the WIN/WIN approach. Using Theorem 1 in time g(k, c Π )|V (T )| 3 log |V (T )| we either find a c Π + k + 2-jungle, which is sufficient to provide a negative answer (recall that a c Π + k + 2-jungle is an obstacle for admitting pathwidth less than c Π + k + 1), or a path decomposition of width O((c Π + k) 2 ), on which we can run the algorithm given by Theorem 6 applied to formula ϕ.

C Width parameters of semi-complete digraphs
In this section we gather results on the relations between width parameters of semi-complete digraphs.

C.1 Definitions
In this subsection we formally define cutwidth and cliquewidth.
Let D be a digraph and let (v 1 , v 2 , . . . , v n ) be an ordering of V (D). By cutwidth of this ordering we mean the value defined as max =1,. ..,n−1 In other words, for every cut between two consecutive vertices we measure the number of edges directed back, and take maximum of these values. By cutwidth of the digraph D, ctw(D), we denote the minimum cutwidth among all possible orderings of vertices.
Let D be a digraph and k be a positive integer. A k-digraph is a digraph whose vertices are labeled by integers from {1, 2, . . . , k}. We call the k-digraph consisting of exactly one vertex labeled by some integer from {1, 2, . . . , k} an initial k-digraph. The clique-width cw(D) is the smallest integer k such that G can be constructed by means of repeated application of the following four operations on k-digraphs: (1) introduce: construction of an initial k-graph labeled by i and denoted by i(v) (that is, i(v) is a k-digraph with v as a single vertex and label i), (2) disjoint union (denoted by ⊕), (3) relabel: changing all labels i to j (denoted by ρ i→j ), and (4) join: connecting all vertices labeled by i with all vertices labeled by j by arcs (denoted by η i,j ). Using the symbols of these operations, we can construct well-formed expressions. An expression is called k-expression for D if the digraph produced by performing these operations, in the order defined by the expression, is isomorphic to G when labels are removed, and cw(D) is the minimum k such that there is a k-expression for D. Proof. We provide a method of construction of a path decomposition of width at most 2c from an ordering of V (D) of cutwidth c.

C.2 Comparison of the parameters
Let be the set of edges (v j , v i ) such that j > i; edges from F will be called back edges. We construct a path decomposition W = (W 1 , W 2 , . . . , W n−1 , W n ) of D by setting In other words, for each cut between two consecutive vertices in the order (plus one extra at the end of the ordering) we construct a bag that contains endpoints of all the back edges that are cut by this cut plus the last vertex. Observe that |W | ≤ 2c + 1 for every 1 ≤ ≤ n − 1. It is easy to construct W in O(|V (D)| 2 ) time using one scan through the ordering (v 1 , v 2 , . . . , v n ) and maintaining the number of back edges incident to every vertex at each point. We are left with arguing that W is a path decomposition. Clearly n i=1 W i = V (D). Consider any vertex v and an index j = , such that v ∈ W j . Assume first that j < . By the definition of W , there exists an index i ≤ j such that (v , v i ) ∈ E(D). Existence of this arc implies that v has to be contained in every bag between W j and W . A symmetrical reasoning works also for j ≥ . We infer that for every vertex v the set of bags it is contained in form an interval in the path decomposition. The claim that W i ∩ W k ⊆ W j for every 1 ≤ i < j < k ≤ n follows directly from this observation.
To finish the proof, consider any edge Proof. We provide a method of construction of a p + 2-expression from a path decomposition of width p.
Let (W 1 , W 2 , . . . , W r ) be a path decomposition of T of width p. By standard means we can assume that the given path decomposition is a nice path decomposition, i.e., Every path decomposition can be easily turned into a nice one of the same width in O(|V (T )| 2 ) time. Intuitively, between every two bags of the given decomposition we firstly forget the part that needs to be forgotten, and then introduce the part that needs to be introduced. As every vertex is introduced and forgotten exactly once, we have that r = 2|V (T )|.
We now build a p + 2-expression that constructs the semi-complete digraph T along the path decomposition. Intuitively, at each step of the construction, every vertex of the bag W i is assigned a different label between 1 and p + 1, while all forgotten vertices are assigned label p + 2. If we proceed in this manner, we will end up with the whole digraph T labeled with p + 2, constructed for the last bag. As we begin with an empty graph, we just need to show what to do in the introduce and forget vertex steps.

Introduce vertex step.
Assume that W i = W i−1 ∪ {v}, i.e., bag W i introduces vertex v. Note that this means that |W i−1 | ≤ p. As labels from 1 up to p + 1 are assigned to vertices of W i−1 and there are at most p of them, let q be a label that is not assigned. We perform following operations; their correctness is straightforward.
• perform ⊕q(v): we introduce the new vertex with label q; • for each w ∈ W i−1 with label q , perform join η q,q if (v, w) ∈ E(D) and join η q ,q if (w, v) ∈ E(D); • perform join η q,p+2 if the new vertex has an outgoing arc to every forgotten vertex.

D Monadic Second-Order logic and tournaments
In this section we recall the definitions of Monadic Second-Order logic and discuss its links to the current work on semi-complete digraphs.
MSO 1 is Monadic Second-Order Logic with quantification over subsets of vertices but not of arcs. The syntax of MSO 1 of digraphs includes the logical connectives ∨, ∧, ¬, ⇔, ⇒, variables for vertices, and sets of vertices, the quantifiers ∀, ∃ that can be applied to these variables, and the following three binary relations: 1. u ∈ U where u is a vertex variable and U is a vertex set variable; 2. A(u, v), where u, v are vertex variables, and the interpretation is that there exists an arc (u, v) in the graph;

equality of variables representing vertices and sets of vertices.
MSO 2 is the natural extension of MSO 1 with quantification also over arcs and subsets of arcs; here, one can additionally check incidency relation between arcs and vertices, i.e., whether a vertex is the head/tail of a given arc. In undirected setting, it is widely known that model checking of formulas of MSO 2 is fixed-parameter tractable, when the parameters are the length of the formula and the treewidth of the graph. As far as MSO 1 is concerned, model checking of formulas of MSO 1 is fixed-parameter tractable, when the parameters are the length of the formula and the cliquewidth of the graph. These results in fact hold not only for undirected graphs, but for structures with binary relations in general, in particular for digraphs. The following result follows from the work of Courcelle, Makowsky and Rotics [20]; we remark that the original paper treats of undirected graphs, but in fact the results hold also in the directed setting (cf. [32, 34, 39]).

Theorem 7.
There exist an algorithm with running time f (||ϕ||, k)|V (T )| 2 that given an MSO 1 formula ϕ checks whether ϕ is satisfied in a semi-complete digraph T , given together with a kexpression constructing it.
Lemma 8 assert that cliquewidth of a tournament is bounded its pathwidth plus 2. Moreover, the proof gives explicit construction of the corresponding expression. Hence, Theorem 6 follows as an immediate corollary. We note that as Lemmas 7 and 8 show essentially the same for cutwidth, the analogous result holds also for cutwidth.
It is tempting to conjecture that the tractability for MSO 1 and pathwidth or cutwidth could be extended also to MSO 2 , as the decompositions resemble treewidth in the undirected setting. We use the following lemma to shows that this is unfortunately not true.

Lemma 9.
There exists a constant-size MSO 2 formula ψ over a signature enriched with three unary relations on vertices, such that checking whether ψ is satisfied in a transitive tournament is NP-hard.
Before we prove the lemma, let us shortly deliberate on how Theorem 5 follows from it. Observe that one can replace each vertex with a constant size subdigraph that encodes satisfaction of unary relations. In ψ we then replace the unary relations with constant size tests, thus obtaining a constant size formula ψ , whose model checking on semi-complete digraphs of constant pathwidth and cutwidth is NP-hard.
Proof of Lemma 9. We provide a polynomial-time reduction from the 3-CNF-SAT problem. We are given a boolean formula ϕ with n variables x 1 , x 2 , . . . , x n and m clauses C 1 , C 2 , . . . , C m . We are to construct a transitive tournament T with three unary relations on vertices such that ϕ is satisfiable if and only if ψ, the constant size MSO 2 formula that will be constructed while describing the reduction, is true in T . Intuitively, the unary relations in T will encode the whole formula ϕ, while ψ is simply an MSO 2 -definable check that nondeterministically guesses the evaluation of variables and checks it.
We will use three unary relations on vertices, denoted P , B and C. The tournament consists of m(2n+1)+1 vertices v 0 , v 1 , . . . , v m(2n+1) , where the edge set is defined as We define B (border) to be true in v i if and only if 2n + 1|i. Thus, the whole tournament is divided into m intervals between consecutive vertices satisfying B, each of size 2n. Each of these intervals will be responsible for checking one of the clauses. The 2n vertices in each interval correspond to literals of variables of ϕ. We define P (parity) to be satisfied in every second vertex of each interval, so that P is satisfied in the first vertex of each interval. The first pair of vertices corresponds to literals x 1 , ¬x 1 , the second to x 2 , ¬x 2 etc. In the i-th interval we make the C (check) relation true in vertices corresponding to literals appearing in the clause C i . This concludes the construction.
We now build the formula ψ that checks existence of an assignment satisfying ϕ. The correctness of the reduction will follow directly from the construction of ψ.
Firstly, we quantify existentially over a subset of edges M and subset of vertices X. X will be a set of all vertices corresponding to literals that are true in the assignment. We will construct ψ in such a manner that M will be exactly the set of arcs We use M to transfer information on the assignment between consecutive intervals.
Formally, in ψ we express following properties of X and M (their expressibility in MSO 2 by formulas of constant size is straightforward): (1) (v 2n+1 , v 0 ) ∈ M (note that v 0 and v 2n+1 can be defined as the first and second vertex satisfying B).
(2) For every two pairs of consecutive vertices (3) For every subset N ⊆ M , if N satisfies (1) and (2) then N = M .
(4) Vertices satisfying B are not in X.
(5) For every two consecutive vertices v i , v i+1 , such that v i , v i+1 / ∈ B, v i ∈ P and v i+1 / ∈ P , exactly one of the vertices v i , v i+1 belongs to X (exactly one literal of every variable is true).
(7) For every interval between two subsequent vertices satisfying B, at least one of the vertices satisfying C belongs to X.
Properties (1), (2) and (3) (4) and (5) assert that in each interval X corresponds to some valid assignment, while property (6) asserts that the assignments in all the intervals are equal. Property (7) checks whether each of the clauses is satisfied.

E Irrelevant vertex in a triple for H-Immersion
In this section we show how to identify a vertex that is irrelevant for H-Immersion problem, in a semi-complete graph containing a sufficiently large triple. Let p(x) = 80x 2 + 80x + 5. We prove the following lemma. Before we proceed to the proof of Lemma 10, we need to make several auxiliary observations. Let η be a solution to H-Immersion instance and let P be the family of paths being images of all the edges in H, i.e., P = η(E(H)). We call an edge (a vertex) used by P, if it belongs to some path from P. We omit the family P whenever it is clear from the context. An edge (a vertex) which is not used is called a free edge (vertex).

Observation 1.
If P is a family of paths containing simple paths only, then every vertex in T is adjacent to at most k used ingoing edges and at most k used outgoing edges.
Proof. Otherwise, there is a path in the solution that visits that vertex at least two times. Therefore, there is a cycle in this path, which contradicts its simplicity.
Let Q = η(E(H)) be the family of paths, where η is the solution to H-Immersion instance I that minimizes the total sum of paths lengths. Firstly, we observe some easy properties of Q.
Observation 2. Every path from Q uses at most 2 edges from the matching between C and A.
Proof. Assume otherwise, that there is a path P ∈ Q that uses three edges of the matching: (c 1 , a 1 ), (c 2 , a 2 ), (c 3 , a 3 ), appearing in this order on the path. By Observation 1, for at most k vertices v ∈ B the edge (a 1 , v) is used. For the same reason, for at most k vertices v ∈ B the edge (v, c 3 ) is used. As |B| > 2k, there exists v ∈ B such that (a 1 , v) and (v, c 3 ) are not used. Now replace the part of P appearing between a 1 and c 3 with a 1 → v → c 3 . We obtain an immersion with smaller sum of lengths of the paths, a contradiction.
Observation 3. Every path from Q uses at most 2k + 4 vertices from A.
Proof. Assume otherwise, that there is a path P ∈ Q passing through at least 2k + 5 vertices from A. By Observation 2, at most 2k of them are endpoints of used edges of the matching between C and A. Therefore, there are at least 5 visited vertices, which are endpoints of an unused edge of the matching. Let us denote any 5 of them by a 1 , a 2 , a 3 , a 4 , a 5 and assume that they appear on P in this order. Let (c 5 , a 5 ) be the edge of the matching between C and A that is adjacent to a 5 . By the same reasoning as in the proof of Observation 2, there exists a vertex v ∈ B, such that (a 1 , v) and (v, c 5 ) are unused edges. Substitute the part of the path P between a 1 and a 5 by the path a 1 → v → c 5 → a 5 , which consists only of unused edges. We obtain an expansion with smaller sum of lengths of the paths, a contradiction.
A symmetrical reasoning yields the following observation. Proof. Assume otherwise, that there is a path P ∈ Q such that it passes through at least 5 vertices from B. Let us denote any 5 of them by b 1 , b 2 , b 3 , b 4 , b 5 and assume that they appear on P in this order. By Observation 1 there are at most k ingoing edges adjacent to b 1 used, and there are at most k outgoing edges adjacent to b 5 used. Moreover, by Observation 2 there are at most 2k edges of the matching between C and A used. As p(k) > 4k, we conclude that there is an unused edge of the matching (c, a), such that edges (b 1 , c) and (a, b 5 ) are also unused. Substitute the part of the path P between b 1 and b 5 with the path b 1 → c → a → b 5 . We obtain an immersion with smaller sum of lengths of the paths, a contradiction.
From Observations 3-5 we obtain the following corollary. Corollary 1. In the set B there are at least 5k vertices free from Q. Moreover, within the matching between C and A there are at least 4k edges having both endpoints free from Q.
We note that the Corollary 1 holds also for much larger values than 5k, 4k, respectively; we choose to state it in this way to show how many free vertices from B and free edges of the matching we actually use in the proof of Lemma 10. We need one more auxiliary lemma that will prove itself useful.
Lemma 11. Let T = (V 1 ∪ V 2 , E) be a semi-complete bipartite graph, i.e., a directed graph, where edges are only between V 1 and V 2 , however, for every v 1 ∈ V 1 and v 2 ∈ V 2 at least one of the edges (v 1 , v 2 ) and (v 2 , v 1 ) is present. Then at least one of the assertions is satisfied: Proof. Assume that (a) does not hold. That means that there is some v 0 ∈ V 1 such that for all v 2 ∈ V 2 we have (v 2 , v 0 ) ∈ E. Then we can always pick v 0 as v 1 in the statement of (b), so (b) holds.
Observe that by reversing all the edges we can obtain a symmetrical lemma, where we assert existence of in-neighbours instead of out-neighbours.
We are now ready to prove Lemma 10. Whenever we will refer to the matching, we mean the matching between C and A.
Proof of Lemma 10. We give an algorithm that outputs a vertex x ∈ B, such that if there exists a solution to the the given instance, then there exists also a solution in which no path passes through x. The algorithm will run in time O(p(k) 2 |V (T )| 2 ).
We proceed in three steps. The first step is to identify in O(p(k) 2 |V (T )| 2 ) time a set X ⊆ B, |X| ≥ 16k 2 + 16k + 1, such that if I is a YES instance, then for every x ∈ X there is a solution η with P = η(E(H)) having following properties: • at least 3k vertices of B are free from P; • at least 2k edges of the matching have both endpoints free from P; • if x is accessed by some path P ∈ P from a vertex v, then v ∈ A.
The second step of the proof is to show that one can identify in O(p(k) 2 |V (T )| 2 ) time a vertex x ∈ X such that if I is a yes instance, then there is a solution with P = η(E(H)) having following properties: • at least k vertices of B are free from P; • if x is accessed by some path P ∈ P from a vertex v, then v ∈ A; • if x is left by some path P ∈ P to a vertex v, then v ∈ C.
The final, concluding step the proof of the lemma, is to show that there is a solution P = η(E(H)) such that • No path from P is using x.
We proceed with the first step. Let Q = η(E(H)), where η is the solution for the H-Immersion instance with the minimum sum of lengths of the paths.
For every vertex b ∈ B, we identify two sets: G b , R b . The set R b consists of those inneighbours of b outside A, which are in-neighbours of at least than 6k vertices from B, while G b consists of the rest of in-neighbours of b outside A. Formally, We claim that if |B ∅ | ≥ 16k 2 + 16k + 1, then we can set X = B ∅ .
Take any b ∈ B ∅ . We argue that we can reroute the paths of Q that access b from outside A in such a manner, that during rerouting each of them we use at most one additional free vertex from B and at most one additional edge from the matching. We reroute the paths one by one. Take a path P that accesses b from outside A, and let v be the previous vertex on the path. As G b = ∅, v ∈ R b . Therefore, v has at least 6k out-neighbours in B. Out of them, at most 4k are not free with respect to Q, due to Observation 5, while at most k − 1 were used by previous reroutings. Therefore, there is a vertex b ∈ B ∩ N + (v), such that b is still free. Thus we can substitute usage of the edge (v, b) on P with the path v → b → c → a → b, where (c, a) is an arbitrary edge of the matching that still has both endpoints free, which exists due to using at most k − 1 of them so far.
We are now left with the case, when |B ∅ | < 16k 2 + 16k + 1. Let B g = B \ B ∅ . Then |B g | ≥ 4(16k 2 + 16k + 1). We construct a semi-complete digraph S = (B g , L) as follows. For or v has an out-neighbour in G b 1 . By Lemma 11, for every pair of distinct b 1 , b 2 ∈ B g , there is at least one arc with endpoints b 1 and b 2 , hence S is semi-complete. The definition of S gives raise to a straightforward algorithm constructing it in O(p(k) 2 |V (T )| 2 ) time. Figure 1: Rerouting strategy for a path accessing vertex b from G b .
Let X be the set of vertices of B g that have out-degree at least 6k 2 + 6k in S; note that X can be constructed in O(p(k) 2 ) time. Observe that |X| ≥ 16k 2 +16k +1, as otherwise the sum of the out-degrees in S would be at most (16k 2 + 16k)(|B g | − 1) + (|B g | − 16k 2 − 16k)(6k 2 + 6k − 1), which is smaller than |Bg| 2 for |B g | ≥ 4(16k 2 + 16k + 1). We now claim that for every b ∈ X, every path of Q using vertex b can be rerouted at the cost of using at most two free vertices of B and at most two edges from the matching that have still both endpoints free. We perform reroutings one by one. Assume that there is a path P ∈ Q accessing b from outside A. Let v be the predecessor of b on P . If v ∈ R b , then we use the same rerouting strategy as in the case of large B ∅ . Assume then that v ∈ G b . As b ∈ X, its out-degree in S is at least 6k 2 + 6k. This means that there are at least 6k 2 + 6k vertices b in B g and corresponding vertices Out of these 6k 2 + 6k vertices b , at most 4k are not free due to Observation 5, at most 2k − 2 were used in previous reroutings, which leaves us with at least 6k 2 vertices b still being free. If for any such b we have v b = v, we follow the same rerouting strategy as in the case of large B ∅ . Assume then that these 6k 2 vertices v b are all distinct from v; note that, however, they are not necessarily distinct from each other. As each v b belongs to G b , v b can have at most 6k − 1 out-neighbours in B. Hence, each vertex of V (T ) can occur among these 6k 2 vertices v b at most 6k − 1 times, so we can distinguish at least k + 1 pairwise distinct vertices v b . We have that edges (v, v b ) and (v b , b ) exist, while b is still free. By Observation 1, at most k edges (v, v b ) are used by some paths, which leaves us at least one v b , for which edge (v, v b ) is free. We can now substitute the edge (v, b) a) is an arbitrarily chosen edge from the matching that still has both endpoints free that was not yet used, which exists due to using at most 2k − 2 of them so far. See Fig. 1. After rerouting, remove all loops that could be created on the paths, so that Observation 1 still holds. Observe that in this manner we use additional vertex b that was free, additional one edge (c, a) from the matching, whereas passing the path through v b can spoil at most one edge of the matching that still has both endpoints free, and at most one free vertex from B. This concludes the construction of the set X.
We proceed with the second step of the proof. We mimic the rerouting arguments from the first step to obtain a vertex x ∈ X with the following property: the rerouted family of paths P obtained from previous arguments that can access x only from A, can be further rerouted so that every path can only leave x by accessing some vertex from C.
For every b ∈ X consider sets R b and G b defined similarly as before (again, they can be computed in O(p(k) 2 |V (T )|) time): Assume first that there is some y ∈ X, such that G y = ∅. We argue that we can in such a case set x = y. Firstly, reroute the solution that minimizes the total sum of lengths of the paths obtaining a solution with the family of paths P that uses at most 2k additional free vertices from B and at most 2k additional edges free edges from the matching, but does not access y from outside A. One by one we reroute paths using y. Each rerouting will cost at most one free vertex from B and at most one edge from the matching that has still both endpoints free. Let P be a path from the solution that passes through y and let v ∈ R y be the next vertex on P . The vertex v has at least 8k in-neighbours in B; at most 4k of them could be used by the original solution, at most 2k of them could be used in rerouting during the first phase and at most k − 1 of them could be used during previous reroutings in this phase. Therefore, we are left with at least one vertex y ∈ B that is still free, such that (y , v) ∈ E(T ). We can now substitute the edge (y, v) in P by the path y → c → a → y → v, where (c, a) is an arbitrarily chosen edge from the matching that was not yet used, which exists due to using at most 3k − 1 of them so far.
We are left with the case, when G y is nonempty for all y ∈ X. Construct a digraph S = (X, L ) in a symmetrical manner to the previous construction: we put an edge ( The remark after Lemma 11 ensures that S is semi-complete. Again, S can be computed in O(p(k) 2 |V (T )| 2 ) time.
As |X| ≥ 16k 2 + 16k + 1, there exists x ∈ X, which has in-degree at least 8k 2 + 8k in S ; note that x can be found in O(p(k) 2 ) time. As before, we argue that after the first rerouting phase for x, we can additionally reroute the paths so that every path can leave x only into C. We reroute the paths one by one; each rerouting uses at most two vertices free vertices from B and at most two edges from the matching. As the in-degree of x in S is at least 8k 2 + 8k, we have at least 8k 2 + 8k vertices x ∈ X and corresponding v At most 4k of them were used in Q, at most 2k were used in previous phase of rerouting, and at most 2k − 2 of them were used in this phase of rerouting. This leaves at least 8k 2 vertices x which are still free. If for any of them we have v x = v, we can make the rerouting similarly as in the previous case: we substitute the edge (x, v) with the path x → c → a → x → v, where (c, a) is an arbitrary edge of the matching that still has both endpoints free, which exists due to using at most 4k − 2 of them so far. Assume then, that all vertices v x are distinct from v; note that, however, they are not necessarily distinct from each other. As every for every x we have v x ∈ G x , by the definition of G x the vertices v x can have at most 8k − 1 in-neighbours in X.
This means that every vertex of V (T ) can occur among vertices v x at most 8k − 1 times, which proves that there are at least k + 1 pairwise distinct vertices among them. By Observation 1, for at most k of them the edge connecting to v can be already used, which leaves us with a single vertex x , such that edges (x , v x ) and (v x , v) exist and are not yet used, whereas x is still free. Now we can perform the rerouting as follows: we substitute the edge (x, v) a) is an arbitrary edge from the matching that was still has both endpoints free, which exists due to at most 4k − 2 of them so far. Similarly as before, we use one additional free vertex x from B, one additional edge (c, a) from the matching, whereas usage of v x can spoil at most one free vertex from B and at most one edge from the matching. After this, we delete all the possible loops created on the paths in order to make Observation 1 still hold. This concludes the construction of the vertex x.
To finish the proof, we need to show that after performing two phases of rerouting obtaining a solution η, whose paths can access and leave x only from A and into C, we can reroute every path so that it does not pass through x at all. Note that so far we have used at most 4k vertices from B, so we still have at least k vertices unused.
If x ∈ η(u) for some u ∈ V (H), then we can simply move the image u: we consider η that differs from η by substituting x for x , where x is any free vertex from B that is not in η(V (H)) (k ≥ |V (H)|, so such a vertex exists). Note that we can make this move as x is not a root vertex: the triple does not contain any root vertices. In case when x / ∈ η(V (H)), we can perform the same rerouting scheme for any x that is still free in B. Now, no path uses x, so I = ((H, u 1 , u 2 , . . . , u t ), (T \ {x}, v 1 , v 2 , . . . , v t )) is a YES instance if I was.

F Dynamic programming routine for rooted immersion
In this subsection we present a dynamic programming routine that for rooted digraph (H; v 1 , v 2 , . . . , v t ), rooted semi-complete digraph (T ; w 1 , w 2 , . . . , w t ), and path decomposition of T computes whether there exists an immersion η of H into T such that η(v i ) = w i for all i ∈ {1, 2, . . . , t}. First, we explain the terminology used to describe the constructed parts of immersion model. Then, we proceed to the dynamic programming routine itself. But before all of these, let us give some intuition behind the algorithm.
The main idea of our routine is as follows: we will encode the interaction of the model of H with all the already introduced vertices as sequences of paths. Every such path has to end in the separator, but can begin in any forgotten vertex as it may be accessed from a vertex not yet introduced. In general setting the dynamic program would need to remember this very vertex in order to check whether it can be indeed accessed; that would yield an XP algorithm and, in essence, this is exactly the idea behind the Fradkin and Seymour algorithm. However, if the digraph is semi-complete, then between every not yet introduced vertex and every forgotten vertex there is an edge. Therefore, we do not need to remember the forgotten vertex itself to check accessibility; a marker saying forgotten, together with information about which markers in fact represent the same vertices, will suffice.
We hope that a reader well-familiar with construction of dynamic programs on various decompositions already has a crude idea about how the computation will be performed. Let us proceed with the details in the next subsections.

F.1 Terminology
In the definitions we use two special symbols: F, U; the reader can think of them as an arbitrary element of A \ B (forgotten) and B \ A (unknown), respectively. Let ι : V (T ) → (A ∩ B) ∪ {F, U} be defined as follows: ι(v) = v if v ∈ A ∩ B, whereas ι(v) = F for v ∈ A \ B and ι(v) = U for v ∈ B \ A. Definition 4. Let P be a path. A sequence of paths (P 1 , P 2 , . . . , P h ) is a trace of P with respect to (A, B), if P i , i ∈ {1, 2, . . . , h} are all maximal subpaths of P that are fully contained in A, while the indices in the sequence reflect their ordering on the path P .
Let (P 1 , P 2 , . . . , P h ) be the trace of P with respect to (A, B). An signature of P on (A, B) is a sequence of pairs ((b 1 , e 1 ), (b 2 , e 2 ), . . . , (b h , e h )), where b h , e h ∈ (A ∩ B) ∪ {F}, such that for every i ∈ {1, 2, . . . , h}: • b i is the beginning of path P i if b i ∈ A ∩ B, and F otherwise; • e i is the end of path P i if e i ∈ A ∩ B, and F otherwise.
In other words, b i , e i are images of the beginning and the end of the path P i in the mapping ι. Observe following properties of the introduced notion: • Signature of path P on separation (A, B) depends only on its trace; therefore, we can also consider signatures of traces.
• It can happen that b i = e i = F only if P i consists of only one vertex b i = e i .
• From the definition of separation it follows that only for i = h it can happen that e i = F, as there is no arc from A \ B to B \ A.
• The empty signature corresponds to P entirely contained in B \ A.
• The signature consisting of one term (F, F) corresponds to P entirely contained in A \ B.
Finally, we are able to encode relevant information about a given model of H.

Definition 5.
Let η be an immersion of a digraph H in T . An immersion signature of η on (A, B) is a mapping ρ together with equivalence relation ≡ on the set of all the pairs of form (F, e) appearing in the image of ρ, such that: • for every v ∈ V (H), ρ(v) = ι(η(v)); • for every e ∈ E(H), ρ(e) is a signature of η(e).
• (F, e 1 ) ≡ (F, e 1 ) if and only if markers F in both pairs correspond to the same forgotten vertex before being mapped by ι.
We remark that the same pair of form (F, e) can appear in different signatures; in this case we consider all the appearances as different pairs. The sole purpose of introducing the relation ≡ is forbidding reusage of edges jumping into the forgotten region. We denote the set of possible immersion signatures on separation (A, B) by E (A,B) .
Moreover, all of them can be enumerated in 2 O(k log m+m (log +log m)) time.
Proof. The consecutive terms correspond to: 1. the choice of mapping ρ on V (H); 2. for every edge e ∈ E(H) the complete information about the signature ρ(e): • for every element of A ∩ B, whether it will be the end of some path in the signature, and in this case, the value of corresponding beginning (a vertex from A ∩ B or F), • the ordering of pairs along the signature, • and whether to append a pair of form (b, F) at the end of the signature ρ(e), and in this case, the value of b (a vertex from A ∩ B or F); 3. partition of at most (m + 1)l pairs in all the signatures from ρ(E(H)) into equivalence classes with respect to ≡.
In the last term we made use of Bell numbers B n , for which a trivial bound B n ≤ n n applies.
It is easy to check that using all these information one can reconstruct the whole signature. For every object constructed in the manner above we can check in time polynomial in k, l, m, whether it corresponds to a possible signature. This yields the enumeration algorithm.

F.2 Dynamic programming routine
We are now ready to prove the main theorem of this section.

Theorem 8.
There exists an algorithm that given a distinctly rooted digraph (H; v 1 , v 2 , . . . , v t ) with k vertices and edges and a semi-complete distinctly rooted digraph (T ; w 1 , w 2 , . . . , w t ) together with its path decomposition of width p, checks in time 2 O(k log p+p (log +log p)) |V (T )|, whether H can be immersed into T while preserving roots.
Proof. Let W = (W 1 , . . . , W r ) be a path decomposition of T of width p. We can assume that W is a nice decomposition, i.e. W 1 = W r = ∅ and for every i ∈ {2, . . . , r}, |W i \W i−1 |+|W i−1 \W i | = 1. If W i = W i−1 ∪ {v}, we say that W i introduces v; if W i−1 = W i ∪ {v}, we say that W i forgets v. Via standard arguments, it is easy to check that every path decomposition can be adjusted to be nice in linear time. Intuitively, between every two bags of the given decomposition we firstly forget the part that needs to be forgotten, and then introduce the part that needs to be introduced. We also note remark that for every i ∈ {1, . . . , r}, the sets A = W 1 ∪ · · · ∪ W i and B = W i ∪ · · · ∪ W r form a separation of T with separator W i .
The number of possible signatures on any separation (A, B) from the decomposition is bounded by 2 O(k log p+pl(log +log p)) by Lemma 12. We show how to compute the values of a binary table D (A,B) : E (A,B) → {⊥, } with the following meaning. For ρ ∈ E (A,B) , D (A,B) [ρ] tells, whether there exists a mapping ρ with following properties: • for every i = 1, 2, . . . , t, ρ(v i ) = w i if w i ∈ A and ρ(v i ) = U otherwise; • for every e = (v, w) ∈ E(H), ρ(e) is a correct path trace with signature ρ(e), beginning in ρ(v) if ρ(v) ∈ A and anywhere in A otherwise, ending in ρ(w) if ρ(w) ∈ A and anywhere in A ∩ B otherwise; • path traces ρ(e) are edge disjoint.
Such mapping ρ will be called a partial immersion of H on (A, B).
For the first separation (∅, V (T )) we have exactly one signature with value , being the signature which maps all the vertices into U and all the edges into empty signatures. The result of the whole computation should be the value for the signature for the last separation (V (T ), ∅), which maps all vertices into F and edges into signatures consisting of one pair (F, F). Therefore,