Detours in Directed Graphs

We study two"above guarantee"versions of the classical Longest Path problem on undirected and directed graphs and obtain the following results. In the first variant of Longest Path that we study, called Longest Detour, the task is to decide whether a graph has an (s,t)-path of length at least dist_G(s,t)+k (where dist_G(s,t) denotes the length of a shortest path from s to t). Bez\'akov\'a et al. proved that on undirected graphs the problem is fixed-parameter tractable (FPT) by providing an algorithm of running time 2^{O (k)} n. Further, they left the parameterized complexity of the problem on directed graphs open. Our first main result establishes a connection between Longest Detour on directed graphs and 3-Disjoint Paths on directed graphs. Using these new insights, we design a 2^{O(k)} n^{O(1)} time algorithm for the problem on directed planar graphs. Further, the new approach yields a significantly faster FPT algorithm on undirected graphs. In the second variant of Longest Path, namely Longest Path Above Diameter, the task is to decide whether the graph has a path of length at least diam(G)+k (diam(G) denotes the length of a longest shortest path in a graph G). We obtain dichotomy results about Longest Path Above Diameter on undirected and directed graphs. For (un)directed graphs, Longest Path Above Diameter is NP-complete even for k=1. However, if the input undirected graph is 2-connected, then the problem is FPT. On the other hand, for 2-connected directed graphs, we show that Longest Path Above Diameter is solvable in polynomial time for each k\in{1,\dots, 4} and is NP-complete for every k\geq 5. The parameterized complexity of Longest Path Above Diameter on general directed graphs remains an interesting open problem.


Introduction
In the Longest Path problem, we are given an n-vertex graph G and an integer k. (Graph G could be undirected or directed.) The task is to decide whether G contains a path of length at least k. Longest Path is a fundamental algorithmic problem that played one of the central roles in developing parameterized complexity [46,9,2,36,40,13,12,41,51,26,26,25,42,8].
To further our algorithmic knowledge about the Longest Path problem, Bezáková et al. [7] introduced a novel "above guarantee" parameterization for the problem. For a pair of vertices s, t of an n-vertex graph G, let dist G (s, t) be the distance from s to t, that is, the length of a shortest path from s to t. In this variant of Longest Path, the task is to decide whether a graph has an (s, t)-path of length at least dist G (s, t) + k. The difference with the "classical" parameterization is that instead of parameterizing by the path length, the parameterization is by the offset k.
Longest Detour Parameter: k Input: A graph G, vertices s, t ∈ V (G), and an integer k. Task: Decide whether there is an (s, t)-path in G of length at least dist G (s, t) + k.
Since the length of a shortest path between s and t can be found in linear time, such a parameterization could provide significantly better solutions than parameterization by the path length. Bezáková et al. [7] proved that on undirected graphs the problem is fixedparameter tractable (FPT) by providing an algorithm of running time 2 O(k) ·n. Parameterized complexity of Longest Detour on directed graphs was left as the main open problem in [7]. Our paper makes significant step towards finding a solution to this open problem.
Our results. Our first main result establishes a connection between Longest Detour and another fundamental algorithmic problem p-Disjoint Paths. Recall that the p-Disjoint Paths problem is to decide whether p pairs of terminal vertices (s i , t i ), i ∈ {1, . . . , p}, in a (directed) graph G could be connected by pairwise internally vertex disjoint (s i , t i )-paths. We prove (the formal statement of our result is given in Theorem 4) that if C is a class of (directed) graphs such that p-Disjoint Paths admits a polynomial time algorithm on C for p = 3, then Longest Detour is FPT on C. Moreover, the FPT algorithm for Longest Detour on C is single-exponential in k (running in time 2 O(k) · n O(1) ).
Unfortunately, our result does not resolve the question about parameterized complexity of Longest Detour on directed graphs. Indeed, Fortune, Hopcroft, and Wyllie [29] proved that p-Disjoint Paths is NP-complete on directed graphs for every fixed p ≥ 2. However, the new insight helps to establish the tractability of Longest Detour on planar directed graphs, whose complexity was also open. The theorem of Schrijver from [48] states that p-Disjoint Paths could be solved in time n O(p) when the input is restricted to planar directed graphs. (This result was improved by Cygan et al. [17] who proved that p-Disjoint Paths parameterized by p is FPT on planar directed graphs.) Pipelined with our theorem, it immediately implies that Longest Detour is FPT on planar directed graphs.
Besides establishing parameterized complexity of Longest Detour on planar directed graphs our theorem has several advantages over the previous work even on undirected graphs. By the seminal result of Robertson and Seymour [47], p-Disjoint Paths is solvable in f (p) · n 3 time on undirected graphs for some function f of p only. Therefore on undirected graphs p-Disjoint Paths is solvable in polynomial time for every fixed p, and for p = 3 in particular. Later the result of Robertson and Seymour was improved by Kawarabayashi, Kobayashi, and Reed [38] who gave an algorithm with quadratic dependence on the input size. Pipelined with our result, this brings us to a Monte Carlo randomized algorithm solving Longest Detour on undirected graphs in time 10.8 k · n O(1) . Our algorithm can be derandomized, and the deterministic algorithm runs in time 45.5 k · n O(1) . While the algorithm of Bezáková et al. [7] for undirected graphs runs in time O(c k · n), that is, is single-exponential in k, the constant c is huge. The reason is that their algorithm exploits the Win/Win approach based on excluding graph minors. More precisely, Bezáková et al. proved that if a 2-connected graph G contains as a minor, a graph obtained from the complete graph K 4 by replacing each edge by a path with k edges, then G has an (s, t)-path of length at least dist G (s, t) + k. Otherwise, in the absence of such a graph as a minor, the treewidth of G is at most 32k + 46. Combining this fact with an FPT 3-approximation algorithm [11], running in time 2 O(k) · n O(1) , to compute the treewidth of a graph, brings us to a graph of treewidth at most 96k + O(1). Finally, solving Longest Detour on graphs of bounded treewidth by one of the known single-exponential algorithms, see [18,10,27], will result in running time 3 96k · n O(1) . Thus on undirected graphs, our algorithm reduces the constant c in the base of the exponent from 3 96 down to 10.8! Our second set of results addresses the complexity of the problem strongly related to Longest Detour. The length of a longest shortest path in a graph G is denoted by diameter of G, diam(G). Thus every graph G has a path of length at least diam(G). But does it have a path of length longer than diam(G)? This leads to the following parameterized problem.

Longest Path above Diameter
Parameter: k Input: A graph G and an integer k. Task: Decide whether there is a path in G of length at least diam(G) + k.
As in Longest Detour, the parameterization is by the offset k. When (s, t) is a pair of diametral vertices in G, the length of the shortest (s, t)-path in G is the diameter of G. However, this does not allow to reduce Longest Path above Diameter to Longest Detour-if there is a path of length diam(G) + k in G, it is not necessarily an (s, t)-path. Moreover, such a path might connect two vertices with a much smaller distance between them than diam(G). In fact, our hardness results for Longest Path above Diameter are based precisely on instances where the target path has this property: its length is very close to diam(G), but much larger than the shortest distance between its endpoints. Thus, the lower bounds we obtain for Longest Path above Diameter are not applicable to Longest Detour.
We obtain the following dichotomy results about Longest Path above Diameter on undirected and directed graphs. For undirected graphs, Longest Path above Diameter is NP-complete even for k = 1. However, if the input undirected graph is 2-connected, that is, S TA C S 2 0 2 2 29:4

Detours in Directed Graphs
it remains connected after deleting any of its vertices, then the problem is FPT. For directed graphs, the problem is also NP-complete even for k = 1. However, the situation is more complicated and interesting on 2-connected directed graphs. (Let us remind that a strongly connected digraph G is 2-connected or strongly 2-connected, if for every vertex v ∈ V (G), graph G − v remains strongly connected.) In this case, we show that Longest Path above Diameter is solvable in polynomial time for each k ∈ {1, . . . , 4} and is NP-complete for every k ≥ 5.
Our approach. A natural way to approach Longest Detour on directed graphs would be to mimic the algorithm for undirected graphs. By the result of Kawarabayashi and Kreutzer [39], every directed graph of sufficiently large directed treewidth contains a sizable directed grid as a "butterfly minor". However, as reported in [6], there are several obstacles towards applying the grid theorem of Kawarabayashi and Kreutzer for obtaining a Win/Win algorithm. After several unsuccessful attempts, we switched to another strategy.
We start the proof of Theorem 4 by checking whether G has an (s, t)-path of length dist G (s, t) + ℓ for k ≤ ℓ < 2k. This can be done in time 2 O(k) · n O(1) by calling the algorithm of Bezáková et al. [7] that finds an (s, t)-path in a directed G of length exactly dist G (s, t) + ℓ. If such a path is not found, we conclude that if (G, k) is a yes-instance, then G contains an (s, t)-path of length at least dist G (s, t) + 2k.
Next, we check whether there exist two vertices v and w reachable from s such that dist G (s, w) − dist G (s, v) ≥ k and G has pairwise disjoint (s, w)-, (w, v)-, and (v, t)-paths. If such a pair of vertices exists, we obtain a solution by concatenating disjoint (s, w)-, (w, v)-, and (v, t)-paths. This is the place in our algorithm, where we require a subroutine solving 3-Disjoint Paths.
When none of the above procedures finds a detour, we prove a combinatorial claim that allows reducing the search of a solution to a significantly smaller region of the graph. This combinatorial claim is the essential part of our algorithm. More precisely, we show that there are two vertices u and x, and a specific induced subgraph H of G (depending on u and x) such that G has an (s, t)-path of length at least dist G (s, t) + k if and only if H has an (u, x)-path of length at least ℓ for a specific ℓ ≤ 2k (also depending on u and x). Moreover, given u, in polynomial time, we can find a feasible domain for vertex x, and for each choice of x, we can also determine ℓ and construct H in polynomial time. Then we apply the algorithm of Fomin et al. [28] to check whether H has an (u, x)-path in H of length at least ℓ.
Our strategy for Longest Path above Diameter is different. For undirected graphs, the solution turns out to be reasonably simple. It easy to show that Longest Path above Diameter is NP-complete for k = 1 by reducing Hamiltonian Path to it. When an undirected graph G is 2-connected, and the diameter is larger than k + 1, then G always contains a path of length at least d + k. If the diameter is at most k, it suffices to run a Longest Path algorithm to show that the problem is FPT. For directed graphs, a similar reduction shows that the problem is NP-complete for k = 1. However, for 2-stronglyconnected directed graphs, the situation is much more interesting. It is not too difficult to prove that when the diameter of a 2-strongly-connected digraph is sufficiently large, it always contains a path of length diam(G) + 1. With much more careful arguments, it is possible to push this up to k = 4. Thus for each k ≤ 4, the problem is solvable in polynomial time. For k = 5 we can construct a family of 2-strongly-connected digraphs of arbitrarily large diameter that do not have a path of length diam(G) + 5. These graphs become extremely useful as gadgets that we use to prove that the problem is NP-complete for each k ≥ 5.
Longest Detour was introduced by Bezáková et al. in [7]. They gave an FPT algorithm for undirected graphs and posed the question about detours in directed graphs. Even the existence of a polynomial time algorithm for Longest Detour with k = 1, that is, deciding whether a directed graph has a path longer than a shortest (s, t)-path, is open. For the related Exact Detour problem, deciding whether there is a detour of length exactly dist G (s, t) + k is FPT both on directed and undirected graphs [7].
Another problem related to our work is Long (s, t)-Path. Here for vertices s and t of a graph G, and integer parameter k, we have to decide whether there is an (s, t)-path in G of length at least k. A simple trick, see [16,Exercise 5.8], allows to use color-coding to show that Long (s, t)-Path is FPT on undirected graph. For directed graphs the situation is more involved, and the first FPT algorithm for Long (s, t)-Path on directed graphs was obtained only recently [28]. The proof of Theorem 4 uses some of the ideas developed in [28].
Both Longest Detour and Longest Path above Diameter fit into the research subarea of parameterized complexity called "above guarantee" parameterization [44,1,15,31,32,33,34,35,43,45]. Besides the work of Bezáková et al. [6], several papers study parameterization of longest paths and cycles above different guarantees. Fomin et al. [23] designed parameterized algorithms for computing paths and cycles longer than the girth of a graph. The same set of the authors in [22] studied FPT algorithms that finds paths and cycles above degeneracy. Fomin et al. [24] developed an FPT algorithm computing a cycle of length 2δ + k, where δ is the minimum vertex degree of the input graph. Jansen, Kozma, and Nederlof in [37] looked at parameterized complexity of Hamiltonicity below Dirac's conditions. Berger, Seymour, and Spirkl in [5], gave a polynomial time algorithm that, with input a graph G and two vertices s, t of G, that decides whether there is an induced (s, t)-path that is longer than a shortest (s, t)-path. All these algorithms for computing long paths and cycles above some guarantee are for undirected graphs.
The remaining part of this paper is organized as follows. In Section 2, we give preliminaries. In Section 3, we prove our first main result establishing connections between 3-Disjoint Paths and Longest Detour (Theorem 4). Section 4 is devoted to Longest Path above Diameter. The concluding Section 5 provides open questions for further research.

Preliminaries
Parameterized Complexity. We refer to the recent books [16,20] for the detailed introduction to Parameterized Complexity. Here we just remind that the computational complexity of an algorithm solving a parameterized problem is measured as a function of the input size n of a problem and an integer parameter k associated with the input. A parameterized problem is said to be fixed- Detours in Directed Graphs edges (arcs, respectively) if this does not create confusion. For a (directed) graph G and a subset X ⊆ V (G) of vertices, we write G[X] to denote the subgraph of G induced by X. For a set of vertices S, G − S denotes the (directed) graph obtained by deleting the vertices of S, that is, ; v 1 and v k are the end-vertices of P and the vertices v 2 , . . . , v k−1 are internal. We say that P is an (v 1 , v k )-path. The length of P , denoted by length(P ), is the number of edges (arcs, respectively) in P . Two paths are disjoint if they have no common vertex and they are internally disjoint if no internal vertex of one path is a vertex of the other. For a (u, v)-path P 1 and a (v, w)-path P 2 that are internally disjoint, we denote by P 1 • P 2 the concatenation of P 1 and G T is a directed graph defined on the same set of vertices and the same set of arcs, but the direction of each arc in G T is reversed.
We use several known parameterized algorithms for finding long paths. First of all, let us recall the currently fastest deterministic algortihm for Longest Path on directed graphs due to Tsur [50].
We also need the result of Fomin et al. [28] for the Long Directed (s, t)-Path problem. This problem asks, given a directed graph G, two vertices s, t ∈ V (G), and an integer k ≥ 0, whether G has an (s, t)-path of length at least k. Clearly, both results holds for the variant of the problem on undirected graphs. Finally, we use the result of Bezáková et al. [7] for the variant of Longest Detour whose task is, given a (directed) graph G, two vertices s, t ∈ V (G), and an integer k ≥ 0, decide whether G has an (s, t)-path of length exactly dist G (s, t) + k.
▶ Proposition 3 ([7]). There is a bounded-error randomized algorithm that solves Exact Detour on undirected graphs in time 2.746 k · n O(1) and on directed graphs in time 4 k · n O(1) . For both undirected and directed graphs, there is a deterministic algorithm that runs in time 6.745 k · n O(1) .

An FPT algorithm for finding detours
In this section we show the first main result of our paper. Proof. Let (G, s, t, k) be an instance of Longest Detour with G ∈ C. For k = 0, the problem is trivial and we assume that k ≥ 1. We also have that (G, s, t, k) is a trivial no-instance if t is not reachable from s. We assume from now that every vertex of G is reachable from s. Otherwise, we set G := G[R], where R is the set of vertices of G reachable from s using the straightforward property that every (s, t)-path in G is a path in G [R].
Clearly, R can be constructed in O(n + m) time by the breadth-first search.
Using Proposition 3, we check in 6.745 2k · n O(1) time by a deterministic algorithm (in 4 2k · n O(1) time by a randomized algorithm, respectively) whether G has an (s, t)-path of length dist G (s, t) + ℓ for some k ≤ ℓ ≤ 2k − 1 by trying all values of ℓ in this interval. We return a solution and stop if we discover such a path. Assume from now that this is not the case, that is, if (G, s, t) is a yes-instance, then the length of every (s, t)-path of length at least dist G (s, t) + k is at least dist G (s, t) + 2k.
We perform the breadth-first search from s in G. For an integer i ≥ 0, denote by L i the set of vertices at distance i from s. Let ℓ be the maximum index such that L ℓ ̸ = ∅. Because every vertex of G is reachable from s, V (G) = ℓ i=0 L i . We call L 0 , . . . , L ℓ BFS-levels. Our algorithm is based on structural properties of potential solutions. Suppose that (G, s, t, k) is a yes-instance and let a path P be a solution of minimum length, that is, P is an (s, t)-path of length at least dist G (s, t) + k and among such paths the length of P is minimum. Denote by p ∈ {1, . . . , ℓ} the minimum index such that L p contains at least two vertices of G. Such an index exists, because if |V (P ) ∩ L i | ≤ 1 for all i ∈ {1, . . . , ℓ}, then P is a shortest (s, t)-path by the definition of L 0 , . . . , L ℓ and the length of P is dist G (s, t) < dist G (s, t) + k as k ≥ 1. Let u be the first (in the path order) vertex of P in L p and let v ̸ = u be the second vertex of P that occurs in L p . Denote by P 1 , P 2 , and P 3 the (s, u), (u, v), and (v, t)-subpath of P , respectively. Clearly, P = P 1 • P 2 • P 3 . Let q ∈ {p, . . . , ℓ} be the maximum index such that P 2 contains a vertex of L q . Then denote by w the first vertex of P 2 in L q . See Figure 1 for the illustration of the described configuration. We use this notation for a (hypothetical) solution throughout the proof of the theorem. The following claim is crucial for us.
▷ Claim 5. The length of P 2 is at least k.
Proof of Claim 5. For the sake of contradiction, assume that the length of P 2 is less than k. Let Q be a shortest (s, v)-path in G. By the definition of BFS-levels, V (Q) ⊆ L 0 ∪ · · · ∪ L p and v is a unique vertex of Q in L p . This implies that Q is internally vertex disjoint with P 3 . Note that the length of Q is the same as the length of P 1 , because P 1 contains exactly one vertex from each of the BFS levels L 1 , . . . , L p . Then P ′ = Q • P 3 is an (s, t)-path and length(P ′ ) =length(Q) + length(P 3 ) = length(P 1 ) + length(P 3 ) =length(P ) − length(P 2 ) ≤ length(P ) − k.

Detours in Directed Graphs
Recall that the length of every (s, t)-path of length at least dist G (s, t) + k is at least dist G (s, t) + 2k. This means that length(P ) ≥ dist G (s, t) + 2k and, therefore, the length of P ′ is at least dist G (s, t) + k, that is, P ′ is a solution to the considered instance. However, length(P ′ ) < length(P ), because P 2 contains at least one arc. This contradicts the choice of P as a solution of minimum length. This completes the proof of the claim. ◁ By Claim 5, solving Longest Detour on (G, s, t, k) boils down to identifying internally disjoint P 1 , P 2 , and P 3 , where the length of P 2 is at least k.
First, we check whether we can find paths for q − p ≥ k − 1. Notice that if q − p ≥ k − 1, then for every internally disjoint (s, w)-, (w, v)-, and (v, t)-paths R 1 , R 2 , and R 3 respectively, their concatenation R 1 • R 2 • R 3 is an (s, t)-path of length at least dist G (s, t) + k. Recall that G ∈ C and p-Disjoint Paths can be solved in polynomial time on this graph class for p = 3. For every choice of two vertices w, v ∈ V (G), we solve p-Disjoint Paths on the instance (G, (s, w), (w, v), (v, s)). Then if there are paths R 1 , R 2 , and R 3 forming a solution to this instance, we check whether length(R 1 ) + length(R 2 ) + length(R 3 ) ≥ dist G (s, t) + k. If this holds, we conclude that the path R 1 • R 2 • R 3 is a solution to the instance (G, s, t, k) of Longest Detour and return it. Assume from now that this is not the case, that is, we failed to find a solution of this type. Then we can complement Claim 5 by the following observation about our hypothetical solution P .
This means that we can assume that k ≥ 2 and have to check whether we can identify P 1 , For this, we go over all possible choices of u. Note that the choice of u determines p, i.e., the index of the BFS-level containing u. We consider the following two cases for each considered choice of u.

Figure 2
The structure of paths P1, P2, and P3 in Case 1. Figure 2). Then dist G (s, t) = r and (G, s, t, k) is a yes-instance if and only if G[L p ∪ · · · ∪ L ℓ ] has a (u, t)-path S of length at least (r − p) + k, because the (s, u)-subpath of a potential solution should be a shortest (s, u)-path. Since r − p ≤ k − 2, we have that (r − p) + k ≤ 2k − 2 and we can find S in 4.884 2k · n O(1) time by Proposition 2 if it exists. If we obtain S, then we consider an arbitrary shortest (s, u)-path S ′ in G and conclude that S ′ • S is a solution. This completes Case 1.
Case 2. t ∈ L r for some r ≥ p + k − 1 (see Figure 3). We again consider our hypothetical solution P = P 1 • P 2 • P 3 . Let H = G[L p+k−1 ∪ · · · ∪ L ℓ ]. Denote by X the set of vertices x ∈ V (H) such that t is reachable from x in H. Denote by x the first vertex of P 3 in X. Clearly, such a vertex exists because t ∈ X. Moreover, x ∈ L p+k−1 and its predecessor y in P 3 is in L p+k−2 . Otherwise, t would be reachable from y ∈ V (H) in H contradicting the choice of x. Let Q 1 and Q 2 be the (v, y)-and (x, t)-subpaths of P 3 . Then We show one more claim about the hypothetical solution P .  Figure 3 The structure of paths P1, P2, and P3 in Case 2.
Proof of Claim 7. The proof is by contradiction. Assume that z ∈ V (Q 1 ) ∩ X. Then t is reachable from z in H. However, x is the first vertex of P 3 with this property by the definition; a contradiction. ◁ 3 is a solution, because length(P 2 ) ≥ k. This allows us to conclude that (G, s, t, k) has a solution (for the considered choice of u) if and only if there is y ∈ L p+k−2 such that (i) there is x ∈ X such that (y, x) ∈ A(G), and (ii) the graph G[L p ∪ · · · ∪ L ℓ ] − X has a (u, y)-path of length at least 2k − 2.
Our algorithm proceeds as follows. We construct the set X using the breadth-first search in O(n + m) time. Then for every y ∈ L p+k−2 we check (i) whether there is x ∈ X such that (y, x) ∈ A(G), and (ii) whether G[L p ∪ · · · ∪ L ℓ ] − X has a (u, y)-path S of length at least 2k − 2. To verify (ii), we apply Proposition 2 that allows to perform the check in 4.884 2k · n O(1) time. If we find such a vertex y and path S, then to obtain a solution, we consider an arbitrary shortest (s, u)-path S ′ and an arbitrary (x, t) path S ′′ in G[X]. Then P ′ = S ′ • S • yx • S ′′ is a required solution to (G, s, t, k). This concludes the analysis in Case 2 and the construction of the algorithm.
The correctness of our algorithm has been proved simultaneously with its construction. The remaining task is to evaluate the total running time. Recall that we verify in 6.745 2k ·n O(1) time whether G has an (s, t)-path of length dist G (s, t) + ℓ for some k ≤ ℓ ≤ 2k − 1 by a deterministic algorithm, and we need 4 2k · n O(1) time if we use a randomized algorithm.

29:10 Detours in Directed Graphs
In particular, combining Theorem 4 with the results of Cygan et al. [17], we obtain the following corollary. Using the fact that p-Disjoint Paths can be solved in O(n 2 ) time by the results of Kawarabayashi, Kobayashi, and Reed [38], we immediately obtain the result for Longest Detour on undirected graphs. However, we can improve the running time of a randomized algorithm by tuning our algorithm for the undirected case. Proof. The deterministic algorithm is the same as in the directed case. To obtain a better randomized algorithm, we follow the algorithm from Theorem 4 and use the notation introduced in its proof. Let (G, s, t, k) be an instance of Longest Detour with G ∈ C. We assume without loss of generality that k ≥ 1 and G is connected. Using Proposition 3, we check in 2.746 2k · n O(1) time by a randomized algorithm whether G has an (s, t)-path of length dist G (s, t) + ℓ for some k ≤ ℓ ≤ 2k − 1. If we fail to find a solution this way, we construct the BFS-levels L 0 , . . . , L ℓ .
Suppose that (G, s, t, k) is a yes-instance with a hypothetical solution P composed by the concatenation of P 1 , P 2 , and P 3 as in the proof of Theorem 4. Let also L p and L q be the corresponding BFS-levels. Observe that if q − p ≥ k/2, then length(P 2 ) ≥ k, because for every edge {x, y} of G, x and y are either in the same BFS-level or in consecutive levels contrary to the directed case where we may have an arc (x, y) where x ∈ L i and y ∈ L j for arbitrary j ∈ {0, . . . , i}. Recall that for every choice of two vertices w, v ∈ V (G), we solve p-Disjoint Paths on the instance (G, (s, w), (w, v), (v, s)) and try to find a solution to (G, s, t, k) by concatenating the solutions for these instances of p-Disjoint Paths. If we fail to find a solution this way, we can conclude now that q − p ≤ k/2 − 1 improving Claim 6. Further, we pick u and consider two cases.
In Case 1, where t ∈ L r for some p ≤ r ≤ p + k/2 − 1, we now find a (u, t)-path S in G[L p ∪ · · · ∪ L ℓ ] of length at least (r − p) + k ≤ 3k/2 in 4.884 3k/2 · n O(1) time. If such a path exists, we obtain a solution.
In Case 2, where t ∈ L r for some r ≥ p + k/2, we consider H = G[L h+1 ∪ · · · ∪ L ℓ ] for h = p+⌈k/2⌉ and denote by X the set of vertices of the connected component of H containing X. Then for every y ∈ L h we check (i) whether there is x ∈ X such that {y, x} ∈ E(G), and (ii) whether G[L p ∪ · · · ∪ L ℓ ] − X has a (u, y)-path S of length at least k + ⌈k/2⌉ in 4.884 3k/2 · n O(1) time. If such a path exists, we construct a solution containing it in the same way as on the directed case.
The running time analysis is essentially the same as in the proof of Theorem 4. The difference is that now we have that 2.746 2 ≤ 4.884 3/2 < 10.80. This implies that the algorithm runs in 10.8 k · n O(1) time. ◀

Longest Path Above Diameter
In this section, we investigate the complexity of Longest Path above Diameter. It can be noted that this problem is NP-complete in general even for k = 1.
▶ Proposition 10. Longest Path above Diameter is NP-complete for k = 1 on undirected graphs.
Proof. Let G be an undirected graph with n ≥ 2 vertices. We construct the graph G ′ as follows (see Figure 4). Construct a copy of G. Construct a vertex u and make it adjacent to every vertex of the copy of G. Construct two vertices s and t, and then (s, u) and (u, t) paths P s and P t , respectively, of length n − 1. Notice that diam(G) = length(P s ) + length(P t ) = 2n − 2. It is easy to verify that G ′ has a path of length 2n − 1 if and only if G has a path of length n − 1, that is, G is Hamiltonian. Because Hamiltonian Path is well-known to be NP-complete [30], we conclude that Longest Path above Diameter is NP-complete for k = 1 ◀ Proposition 10 immediately implies that Longest Path above Diameter is NPcomplete for k = 1 on strongly connected directed graphs as we can reduce the problem on undirected graphs to the directed variant by replacing each edge by the pair of arcs with opposite orientations. Still, it can be observed that the reduction in Proposition 10 strongly relies on the fact that the constructed graph G ′ has an articulation point u. Hence, it is natural to investigate the problem further imposing connectivity constraints on the input graphs. And indeed, it can be easily seen that Longest Path above Diameter is FPT on 2-connected undirected graphs.
▶ Observation 11. Longest Path above Diameter can be solved in time 6.523 k · n O(1) on undirected 2-connected graphs.
Proof. Let (G, k) be an instance of Longest Path above Diameter where G is 2connected. If d = diam(G) ≤ k, we can solve the problem in time 2.554 d+k · n O(1) by using the algorithm of Proposition 1 to check whether G has a path of length d + k. Note that 2.554 d+k ≤ 2.554 2k ≤ 6.523 k . Otherwise, if d > k, consider a pair of vertices s and t with dist G (s, t) = d. Because G is 2-connected, by Menger's theorem (see, e.g., [19]), G has a cycle C containing s and t. Since dist G (s, t) = d and d ≥ k + 1, the length of C is at least d + k + 1. This implies that C contains a path of length d + k. ◀ However, the arguments from the proof of Observation 11 cannot be translated to directed graphs. In particular, if a directed graph G is 2-strongly-connected, it does not mean that for every two vertices u and v, G has a cycle containing u and v. We show the following theorem providing a full dichotomy for the complexity of Longest Path above Diameter on 2-strongly-connected graphs.
▶ Theorem 12. On 2-strongly-connected directed graphs, Longest Path above Diameter with k ≤ 4 can be solved in polynomial time, while for k ≥ 5 it is NP-complete.

S TA C S 2 0 2 2
In what remains of this section, we give some intuition behind the proof of Theorem 12; the details can be found in the full version of the paper [21]. To show the positive part of the theorem, it is sufficient to consider graphs with diameter greater than some fixed constant, because in graphs with smaller diameter the problem can be solved in linear time. For graphs with a sufficiently large diameter, we show that a path of length diameter plus four always exists. To construct such a path, we take the diameter pair (s, t) and employ 2-strong-connectivity of the graph to find two disjoint (s, t)-paths and two disjoint (t, s)-paths in the graph. We then show that out of the several possible ways to comprise a path out of the parts of these four paths, at least one always obtains a path of desired length. The most non-trivial case of this construction involves constructing two paths of length five, one ending in a vertex u that is at distance three from s and the other starting in a vertex v from which we can reach t using three arcs. We then concatencate these two paths using a specific (u, v)-path inbetween. Since (s, t) is a diameter pair, the length of any (u, v)-path is at least diameter minus six, so the length of the concatenation is at least diameter plus four. The other cases are analyzed in a similar fashion.
For the lower bound part of Theorem 12, the general idea of the proof is similar to that of Proposition 10. We aim to take a path-like gadget graph, then take a sufficiently large Hamiltonian Path instance and connect it to the middle of the gadget. However, while in the general case it suffices to simply take a path graph (Proposition 10), the 2strongly-connected case is much more technically involved. First, we need a family of gadget graphs that are 2-strongly-connected, have arbitrarily large diameter, but each graph in the family does not have a path longer than diameter plus four. This, in fact, is exactly a counterexample to the positive part of Theorem 12, as the existence of such family of graphs proves that there cannot always be a path of length diameter plus four in a sufficiently large 2-connected directed graph. Additionally, for the reduction we need that graphs in this family behave like paths, specifically that the length of the longest path that ends in the "middle" of the gadget is roughly half of the diameter. Constructing this graph family is a main technical challenge of the theorem. After constructing the gadget graph family the proof is reasonably simple, as we take a 2-connected Hamiltonian Path instance, and connect it to the "middle" of a sufficiently large gadget graph. The connection is done by a simple 4-vertex connector gadget that ensures that the resulting graph is 2-strongly-connected, but only allows for paths that alternate at most once between the gadget graph and the starting instance.

Conclusion
We proved that if C is a class of directed graph such that p-Disjoint Paths is in P on C for p = 3, then Longest Detour is FPT on C. However p-Disjoint Paths is NP-complete on directed graphs for every fixed p ≥ 2 [29]. This leaves open the question of Bezáková et al. [7] about parameterized complexity of Longest Detour on general directed graphs. Even the complexity (P versus NP) of deciding whether a directed graph contains an (s, t)-path longer than dist G (s, t) (the case of k = 1) remains open. Notice that Longest Detour is not equivalent to p-Disjoint Paths for p = 3 and, therefore, the hardness of p-Disjoint Paths does not imply hardness of Longest Detour. Our result implies, in particular, that Longest Detour is FPT on planar directed graphs. There are various classes of directed graphs on which p-Disjoint Paths is tractable for fixed p (see, e.g., the book of Bang-Jensen and Gutin [3]). For example, by Chudnovsky, Scott, and Seymour [14], p-Disjoint Paths can be solved in polynomial time for every fixed p on semi-complete directed graphs. Together with Theorem 4, it implies that Longest Detour is FPT on semi-complete directed graphs and tournaments. However, from what we know, these results could be too weak in the following sense. Using the structural results of Thomassen [49], Bang-Jensen, Manoussakis, and Thomassen in [4] gave a polynomial-time algorithm to decide whether a semi-complete directed graph has a Hamiltonian (s, t)-path for two given vertices s and t. Thus the real question is whether Longest Detour is in P on semi-complete directed graphs or tournaments.
The second part of our results is devoted to Longest Path above Diameter. We proved that this problem is NP-complete for general graphs for k = 1 and showed that it is in FPT when the input graph is undirected and 2-connected. We established the complexity dichotomy for Longest Path above Diameter for the case of 2-strongly-connected directed graphs by showing that the problem can be solved in polynomial time for k ≤ 4 and is NP-complete for k ≥ 5. This naturally leaves an open question for larger values of strong connectivity. The computational complexity of Longest Path above Diameter on t-strongly connected graphs for t ≥ 3 is open. For a very concrete question, is there a polynomial algorithm for Longest Path above Diameter with k = 5 on graphs of strong connectivity 3?