On graphs coverable by k shortest paths

We show that if the edges or vertices of an undirected graph $G$ can be covered by $k$ shortest paths, then the pathwidth of $G$ is upper-bounded by a single-exponential function of $k$. As a corollary, we prove that the problem Isometric Path Cover with Terminals (which, given a graph $G$ and a set of $k$ pairs of vertices called terminals, asks whether $G$ can be covered by $k$ shortest paths, each joining a pair of terminals) is FPT with respect to the number of terminals. The same holds for the similar problem Strong Geodetic Set with Terminals (which, given a graph $G$ and a set of $k$ terminals, asks whether there exist $\binom{k}{2}$ shortest paths covering $G$, each joining a distinct pair of terminals). Moreover, this implies that the related problems Isometric Path Cover and Strong Geodetic Set (defined similarly but where the set of terminals is not part of the input) are in XP with respect to parameter $k$.


Introduction
Path problems such as Hamiltonian Path are among the most fundamental problems in the field of algorithms. Hamiltonian Path can be generalized as the covering problem Path Cover [2], where one asks to cover the vertices of an input graph using a prescribed number of paths. The corresponding packing problem is Disjoint Paths where, given a set of k pairs of terminal vertices of a graph G, one asks whether there are k vertex-disjoint paths in G, each joining two paired terminals. Disjoint Paths is a fundamental problem and a precursor to the field of parameterized complexity due to the celebrated fixed-parameter tractable algorithm devised by Robertson and Seymour [21] for the parameter "number of paths". We recall that in the field of parameterized algorithms and complexity, one studies parameterized problems, whose input I comes together with a parameter k. A parameterized problem is said to be FPT (fixed-parameter tractable) if it can be solved in time f (k) · |I| O (1) , for some computable function f . If the problem can be solved in time O(|I| f (k) ), it belongs to class XP ; see, e.g., [7] for more details.
The name Isometric Path Cover with Terminals comes from the related Isometric Path Cover problem where the terminals are not part of the input, which was introduced in [12] in the context of the Cops and Robbers game on graphs (see also [1]).

Isometric Path Cover
Input: A graph G, and an integer k. Question: Does there exist a set of k shortest paths, such that each vertex of G belongs to at least one of the paths?
Closely related variants of Isometric Path Cover with Terminals and Isometric Path Cover have been studied, in which there are only k terminals, and one asks to find k 2 shortest paths joining each pair of terminals. The version without terminals has been called Strong Geodetic Set in the literature; we call the version with terminals Strong Geodetic Set with Terminals. It was first studied (independently) in [8,9], see also [15].
Strong Geodetic Set with Terminals Input: A graph G, and a set of k vertices of G called terminals. Question: Does there exist a set of k 2 shortest paths, each path joining a distinct pair of terminals, such that each vertex of G belongs to at least one of the paths?
The variant where the terminals are not given in the input was defined in [4] as follows.
Strong Geodetic Set Input: A graph G, and an integer k. Question: Does there exist a set of k terminals and a set of k 2 shortest paths, each path joining a distinct pair of terminals, such that each vertex of G belongs to at least one of the paths?
The complexity of these problems has been studied in the literature. It was shown in [5] that Isometric Path Cover is NP-complete, even for chordal graphs, a class for which the authors of [5] also showed that the problem can be approximated within a constant factor. For general graphs, it was shown in [22] that the problem can be approximated in polynomial time within a factor of O(log d), where d is the diameter of the input graph. It was proven to be polynomial-time solvable on block graphs [20]. It is shown in [8] that Strong Geodetic Set with Terminals is NP-hard. In [9], it is shown that this holds even for bipartite graphs of maximum degree 4 or diameter 6, however Strong Geodetic Set with Terminals is polynomial-time solvable on split graphs, graphs of diameter 2, block graphs, and cactus graphs. We prove here (cf. Proposition 15) that Isometric Path Cover with Terminals is also NP-complete.
All these problems can also be studied in their edge-covering version, where one requires to cover all edges of the input graph by the corresponding shortest paths. For instance, the Strong Edge Geodetic Set problem is studied in [18].

Our results
Our main combinatorial theorem is as follows (see Section 2 for the definition of pathwidth).
▶ Theorem 1. Let G be a graph whose edge set can be covered by at most k shortest paths.
If G is such that its vertex set can be covered by at most k shortest paths, then the pathwidth of G is at most (2k − 1) · f (k).
We actually show that in such a graph G, given an arbitrary vertex a and an integer D, the number of vertices at distance exactly D from a is upper-bounded by a function of k and it does not depend on the size of the input graph. It follows that a very simple linear-time algorithm based on a breadth-first search provides a path decomposition whose width is upper-bounded by the aforementioned function of k. The complexity of the algorithm itself does not depend on k.
Besides the combinatorial bounds, we employ the celebrated theorem of Courcelle [6], stating that problems expressible in Monadic Second-Order Logic (MSOL 2 ) can be solved in linear time for graphs of bounded treewidth (and thus, of bounded pathwidth). More precisely, we reduce the problem Isometric Path Cover with Terminals to an optimization problem expressible in MSOL 2 . The result can also be obtained by dynamic programming but the algorithm would be tedious and not particularly efficient, therefore we prefer the general logic-based framework for further extensions. The running time is linear in n, the number of vertices of the graph, but super-exponential in the parameter k. Together with Theorem 1, this implies the following. Thanks to the flexibility of Monadic Second-Order Logic, our algorithmic results easily extend to the edge-covering versions of our problems, and to variants where we require the paths to be edge-disjoint, or vertex-disjoint (as studied in [17]). The second part of Theorem 2 answers positively a question asked in [15].
After some preliminaries in Section 2, we prove Theorem 1 in Sections 3 and 4. More specifically, Section 3 provides the upper bound on the pathwidth of graphs whose edges are coverable by k shortest paths, then the tools are extended to vertex-coverings in the next section. Algorithmic consequences (Theorem 2) are derived in Section 5, and we conclude with some open questions.

Preliminaries and notations Paths and concatenation operators ⊕ and ⊙
We refer to [10] for usual notations on graphs. In this paper we only consider undirected, unweighted graphs. For simplicity, we assume that our input graph G = (V, E) is connected, though all our combinatorial and algorithmic results extend to non-connected graphs. As usually N (x) denotes the neighbourhood of vertex x.
} is an edge of the graph. We also say that P is an x 1 -x l path. Note that our paths are simple and they do not use twice the same vertex. We denote by V (P ) the vertices of path P , and by E(P ) its edges. Given two vertices x, y ∈ V (P ), we denote by P [x, y] the subpath of P between x and y. Moreover we let |P | denote the length of path P , that is, the number of its edges. The distance between two vertices a and b in G is denoted dist(a, b) and corresponds to the length of a shortest a-b path.
Throughout the paper, we will construct paths by concatenation operations. It is convenient to think of our paths as directed: when we speak of an a-b path, we think of it as being directed from a to b.

Path decompositions through breadth-first search
A path decomposition of G = (V, E) is a sequence P = (X 1 , X 2 , . . . , X q ) of vertex subsets of G, called bags, such that for every edge {x, y} ∈ E there is at least one bag containing both endpoints, and for every vertex x ∈ V , the bags containing x form a continuous sub-sequence of P. The width of P is max{|X i | − 1 | 1 ≤ i ≤ q}, and the pathwidth pw(G) of G is the minimum width over all path decompositions of G.
The treewidth tw(G) of graph G is defined similarly (see e.g. [10]), using a so-called tree decomposition; for our purpose, we only need to know that for any graph G, tw(G) ≤ pw(G), in particular any path decomposition is also a tree decomposition of the same width. We also need the following folklore lemma on path decompositions. Proof. Let ecc(a) be the eccentricity of vertex a (i.e., max x∈V dist(a, x)). For any D with 0 ≤ D ≤ ecc(a) we denote by Layer(D) the set of vertices at distance exactly D from a, i.e. the layers of a breadth-first search on G starting at a. Observe that, by taking as bags the unions Layer(D) ∪ Layer(D + 1) of pairs of consecutive layers, 0 ≤ D < ecc(a), and by ordering them according to D, we obtain a path decomposition of G. Indeed for each edge {x, y} both endpoints are in the same layer or in two consecutive layers, thus will appear in the same bag. For each vertex x, it appears in at most two bags: if d = dist(a, x) then x is in bags Layer(d − 1) ∪ Layer(d) and Layer(d) ∪ Layer(d + 1) (or one bag if d = 0 or d = ecc(a)), and these bags appear consecutively in the decomposition. Since each layer has at most K vertices, the width of this decomposition is at most 2K − 1. ◀

Warm-up: edge-covering with k shortest paths
As a warm-up, we start by proving Theorem 1 in the case when graph G = (V, E) is edgecoverable by k shortest paths. In this case, there is a simple and elegant encoding of shortest paths leading to the desired result; the case of vertex-covering, which is more technical, will be studied in the next section. In this section, G = (V, E) denotes a graph whose edge set is coverable by k shortest paths. Let us fix such a set of paths µ 1 , . . . , µ k , and call them the base paths of G. All constructions in this section are built on this particular set of base paths (without explicitly recalling it for each lemma, in order to ease the notations). We endow each base path µ c , 1 ≤ c ≤ k with an arbitrary direction. E.g., assuming that the vertices of G are numbered from 1 to n, the direction of path P is from its smallest towards its largest end-vertex. A (directed) subpath µ c [x, y] of µ c is given a positive sign + if it follows the direction of µ c , otherwise it is given a negative sign −. For each edge e of G, let colours(e) be the set of all values c ∈ {1 . . . , k} such that e is an edge of µ c .

Good colourings
Let P be an a-b path of G, from vertex a to vertex b. A colouring of P is a function col : E(P ) → {1, . . . , k} assigning to each edge e of the path one of its colours col(e) ∈ colours(e). The colouring col of P is said to be good if, for any colour c, the set of edges using this colour form a connected subpath P [x, y] of P . (Since our paths are simple, this condition entails that P [x, y] = µ c [x, y].) A pair (P, col) formed by a path together with a good colouring is called well-coloured.
Operator ⊙ defined in Section 2 naturally extends to coloured paths. Given a coloured path (P, col), we simply denote by (P [x, y], col) its restriction to a subpath P [x, y] of P . Finally, we define for any path P and any colour 1 ≤ c ≤ k the function monochr c : E(P ) → c. Hence all edges of the coloured path (P, monochr c ) have colour c.
With these notations, any well-coloured a-b path (P, col) with colours (c 1 , . . . , c l ) appearing in this order can be written as ] are the monochromatic subpaths of (P, col), coloured c i . ▶ Lemma 5 (Good colouring lemma). For any pair of vertices a and b of G, there exists a well-coloured a-b path (P, col) such that P is a shortest a-b path.
We will simply call (P, col) a well-coloured shortest a-b path.
Proof. Among all shortest a-b paths, choose one that admits a colouring with a minimum number of monochromatic subpaths. Let P be this path, and col the corresponding colouring. Assume by contradiction that the colouring is not good. Then there exist three edges e 1 = {x 1 , y 1 }, e 2 = {x 2 , y 2 } and e 3 = {x 3 , y 3 }, appearing in this order, such that col(e 1 ) = col(e 3 ) ̸ = col(e 2 ). Assume w.l.o.g. that the vertices appear in the order x 1 , y 1 , x 2 , y 2 , x 3 , y 3 from a to b (note that we my have y 1 = x 2 or y 2 = x 3 ). Let c = col(e 1 ) = col(e 3 ). Therefore y 1 and x 3 are on the same base path µ c . Let P ′ be the path obtained from P by replacing ] is a shortest possible y 1 -x 3 path of graph G (in particular, P ′ has no repeated vertices). Second, in P ′ we can colour all edges of P ′ [y 1 , x 3 ] with colour c, and keep all other colours unchanged. Hence P ′ has strictly fewer monochromatic subpaths than P -a contradiction. ◀

40:6 On Graphs Coverable by k Shortest Paths
Let (P, col) be a well-coloured a-b path, with colours (c 1 , . . . , c l ) in this order. Recall that each monochromatic subpath P [x i , x i+1 ] of P , of colour c i , induces a sign on the corresponding base path µ c (positive if P [x i , x i+1 ] has the same direction as µ c , negative otherwise). Therefore, we can define the colours-signs word ColoursSignsW(P, col) = ((c 1 , s 1 ), (c 2 , s 2 ), . . . , (c l , s l )) on the alphabet {1, . . . , k}×{+, −}, corresponding to the colours and signs of the monochromatic subpaths of P , according to the ordering in which these subpaths appear from a to b. Observe that such words have at most k letters on an alphabet of size 2k. Therefore the number of different words is upper bounded by a function of k: ▶ Lemma 6. The number of possible colours-signs words, over all well-coloured paths of G, Proof. We claim that the number of colours-signs words of l letters is upper bounded by 2 l k! (k−l)! . Observe that the colours form a word of length l, on an alphabet of size k, without repetition. The number of such words is k! (k−l)! (e.g., by choosing l letters among the k possible ones, and applying all possible permutations). Since each letter also has a sign in {+, −}, we multiply this quantity by 2 l , and the conclusion follows by summing over all possible values of l. ◀ The following crucial lemma implies that, given a start vertex a, a distance D and a colours-signs word ω, there is at most one vertex b at distance D from a, such that the well-coloured shortest a-b path respects word ω. This will allow to upper bound the number of vertices at distance D from a. ▶ Lemma 7 (Colours-signs encoding). Consider two vertices b and c at the same distance from some vertex a of G. Let (P, col) be a well-coloured shortest a-b path and (P ′ , col ′ ) be a well-coloured shortest a-c path. If ColoursSignsW(P, col) = ColoursSignsW(P ′ , col ′ ), then b = c.
Let P [a, x 2 ] (resp. P ′ [a, x ′ 2 ]) be the maximal subpath of P (resp. P ′ ) of colour c 1 starting from a. Assume w.l.o.g. that P [a, x 2 ] is at least as long as P ′ [a, x ′ 2 ]. Since both are subpaths of µ c1 , starting from a and having the same sign s 1 w.r.t. µ c1 , we actually have that P ′ [a, x ′ 2 ] is contained in P [a, x 2 ], in particular x ′ 2 is between a and x 2 in P and in µ c1 . Observe that, if word ω has only one letter, P [a, x 2 ] = P and P ′ [a, x ′ 2 ] = P ′ , thus they are all of the same length. Since they are of the same sign w.r.t. µ c1 , this implies that which proves the base case of our induction. Assume now that ω has l ≥ 2 letters and that the lemma is true for words of length l − 1. Consider first the case when P [a, is also the first vertex of the subpaths of colour c 2 of both P and P ′ .
, col ′ ) are well-coloured shortest paths of the same length, and have the same colours-signs word ((c 2 , s 2 ), . . . , (c l , s l )), with l − 1 letters. Hence the property follows by the induction hypothesis.
We now handle the second and last case, when P [a, x 2 ] is strictly longer than P ′ [a, x ′ 2 ]. Let x 3 be the last vertex of the subpath coloured c 2 in (P, col). In particular, x ′ 2 , x 2 and x 3 are all vertices of µ c2 .
Let us make an easy but crucial observation: on µ c2 , vertex x 2 is between x ′ 2 and x 3 . To prove this claim, note that in path P , vertices a, x ′ 2 and x 2 appear in this order (as observed in the beginning of the proof), and by construction x 2 appears between a and x 3 . Therefore a, x ′ 2 , x 2 , x 3 appear in this order on P , which is a shortest path. Hence Since the three vertices x ′ 2 , x 2 , x 3 are all on the shortest path µ c2 , they must appear in this order on it. Consequently, µ c2 [x ′ 2 , x 3 ] induces the same sign s 2 on µ c2 as P [x 2 , In particular, in path ( , coloured c 2 , without changing the total length. We obtain the well-coloured shortest , col). Its colours-signs word is ((c 2 , s 2 ), . . . , (c l , s l )), the same as for the shortest

Vertex-covering with k shortest paths
In this section, G = (V, E) denotes a graph whose vertices can be covered by k shortest paths µ 1 , . . . , µ k . As before we endow each base path µ c with a direction, but now colours are assigned to vertices. We can easily adapt the notions of good colourings of the previous section to these vertex-colourings. Again, for any pair of vertices a and b, there is a well-coloured shortest path joining them (Lemma 9), which defines a colours-signs word. But we shall see that now (unlike in the simpler case of edge-coverings), we may have two distinct vertices b and c at the same distance D from a, and well-coloured shortest a-b and a-c paths with the same colours-signs word. More efforts will be needed to recover a (slightly larger) upper bound on the number of vertices at distance D from a (Corollary 14).

Good colourings
For each vertex v of G, let colours(v) denote the set of indices (colours) c ∈ {1 . . . , k} such that v is a vertex of µ c . Let P be an a-b path of G, from vertex a to vertex b. A colouring of P is a function col : V (P ) → {1, . . . , k} assigning to each vertex v of P one of its colours col(v) ∈ colours(v). A coloured path is a pair (P, col). The colouring col of P is said to be good if, for any colour c, the subgraph induced by the set of vertices using this colour c forms a connected subpath P [x, y] of P (which implies that P [x, y] = µ c [x, y]). A coloured path (P, col) where col is a good colouring is called well-coloured.
Operators ⊕ and ⊙ naturally extend to (vertex) coloured paths, with the precaution that (ν, col) ⊙ (η, col ′ ) is defined only when their common vertex x, the last of ν and first of η, satisfies col(x) = col ′ (x). Given a coloured path (P, col), we again denote by (P [x, y], col) its restriction to a subpath P [x, y] of P . For each colour 1 ≤ c ≤ k, let now (P, monochr c ) denote the monochromatic colouring of V (P ) with colour c.  = a 1 , b 1 , a 2 , b 2 , . . . , a l , b l = b, as in Figure 2.

I S A
Like in the previous section, we have: For any pair of vertices a and b of G, there exists a well-coloured shortest a-b path.
Proof. Among all shortest a-b paths, choose one that admits a colouring with a minimum number of monochromatic subpaths. Let (P, col) be such a coloured path. Assume for a contradiction that the colouring col is not good. Then there exist three vertices x, y and z, appearing in this order in P such that col(x) = col(z) ̸ = col(y). Therefore x and z are on the same base path µ c . Let P ′ be the path obtained from P by replacing Notice that P ′ is no longer than P , since µ c [x, z] is a shortest x-z path of graph G. Moreover, in P ′ we can colour all vertices of P ′ [x, z] with colour c, and keep all other colours unchanged.
Hence P ′ has strictly fewer monochromatic subpaths than P -a contradiction. ◀

Colours-signs word
Let (P, col) be a well-coloured a-b path; we recall that we see it as being directed from a to b. As in Section 3, each monochromatic subpath P ′ of P , say of colour c, induces a sign (+ or −) depending on its direction w.r.t. µ c , if P ′ has at least two vertices. If P ′ has a unique vertex, we assign to it sign +. Therefore, we can again define the colours-signs word ColoursSignsW(P, col) = ((c 1 , s 1 ), (c 2 , s 2 ), . . . , (c l , s l )) on the alphabet {1, . . . , k} × {+, −}, corresponding to the colours and signs of the monochromatic subpaths of P according to the ordering in which these subpaths appear from a to b.
In the case of edge-covering, we had the elegant statement of Lemma 7, by which, given a vertex a, a colours-signs word ω and a distance D, there is a unique vertex b (if any exists) at distance D such that the well-coloured shortest a-b path corresponds to this word. Unfortunately, this does not extend to vertex-covering: Figure 1 presents two distinct vertices b and c located at the same distance D from vertex a, together with a well-coloured shortest a-b path (P, col) and a well-coloured shortest a-c path (P ′ , col ′ ). These coloured paths starting from a have the same colours-signs word and the same length, but this does not imply that their endpoints are equal. a b c P P Figure 1 Two well-coloured paths (P, col) and (P ′ , col ′ ) with same colours-signs word ω = ((red, −), (blue, +)), same length (5) and same start vertex (a), but different end-vertices (b and c).

Canonical well-coloured paths
In order to obtain a situation somewhat similar to the case of edge-covering, we define a canonical representation of well-coloured paths (see Figure 2 for an example). Given a colours-signs word ω = ((c 1 , s 1 ), (c 2 , s 2 ), . . . , (c l , s l )) with no repetition of colours, a start vertex a and a length L, we define a unique well-coloured path CanonPath(ω, a, L) starting from a, of the prescribed length L and having the colours-signs word ω, as follows: 1. If l = 1, let b be the vertex at distance L of a on the path µ c1 w.r.t. s 1 . Then CanonPath(ω, a, L) = (µ c1 [a, b], monochr c1 ). 2. Otherwise, let b 1 be the first vertex of µ c1 starting from a w.r.t. s 1 having a neighbour in µ c2 . Among the vertices of µ c2 adjacent to b 1 , choose a 2 to be the one that appears first in µ c2 , according to its direction. We let: Note that the path CanonPath(ω, a, L) might not exist, e.g. if, in the base case of the construction, a ̸ ∈ µ c1 or the subpath of µ c1 starting from a and following sign s 1 is shorter than L or, in the second step, vertex b 1 does not exist, or |µ c1 [a, b 1 ]| exceeds L. a colours-signs word ω, a vertex a and a length L, if the path (P, col) = CanonPath(ω, a, L) exists, then it is well-coloured. Moreover, this path is unique and satisfies (P, col) = CanonPath(ColoursSignsW(P, col), a, |P |).

▶ Observation 10. Given
Proof. Notice first that, by construction, we have |P | = L and ColoursSignsW(P, col) = ω which implies the last part of the statement. Now since this path is recursively obtained by the concatenation of monochromatic (simple) subpaths (Equation 1), it is well-coloured. The uniqueness of path (P, col) comes from the deterministic choices made during the algorithm, which concludes the proof. To obtain a result similar to Lemma 7, we provide an algorithm that takes as input a well-coloured a-b path P , the corresponding good colouring col with l colours, and that computes a canonical well-coloured a-b path whose length is upper-bounded by |P | + 2(l − 1) (see Algorithm 1 and Lemma 12). As before, let ω = ((c 1 , s 1 ), . . . , (c l , s l )) be the colours-signs word of (P, col) and for each 1 ≤ i ≤ l, let a i (resp. b i ) denote the first (resp. last) vertex of (P, col) coloured c i . Informally, the algorithm recursively computes a coloured path as follows: if l = 1, we let Canonize(P, col) = (P, col). Otherwise, we consider b ′ 1 as the first vertex of P [a, b 1 ] (hence, of µ c1 starting from a following sign s 1 ) having a neighbour in µ c2 (line 4). As in the definition of the CanonPath function, we choose the neighbour a ′ 2 of b ′ 1 to be the vertex of µ c2 that appears first on this path, according to its direction, among the neighbours of b ′ 1 (line 5). We next replace (see line 6 and Figure 3), and then re-apply the transformation on the new path starting from a ′ 2 (line 7). We note that the colours-signs word of the resulting well-coloured path may be different from ω, since a sign of ω might be flipped in the construction of the new path in line 6.
1 ) that appears first on µ c2 according to its direction; ▶ Lemma 12 (canonization of well-coloured paths). Given a well-coloured a-b path (P, col), with a colours-signs word of l letters, the result of Canonize(P, col) is a canonical well-coloured a-b path of length at most |P | + 2(l − 1).
Proof. Denote (P c , col c ) = Canonize(P, col) and let ω c = ColoursSignsW(P c , col c ) be its colours-signs word. We first claim that (P c , col c ) is a canonical well-coloured path, i.e. equal to CanonPath(ω c , a, |P c |) (Definition 11). In order to prove the claim we proceed by induction on the number l of colours of (P, col). The property is true if (P, col) has a unique colour, since in this (base) case, (P c , col c ) = (P, col) (line 3 of Algorithm 1). Otherwise, by induction, (P c , col c ) is formed by (P [a, b ′ 1 ], monochr c1 ) concatenated with (P ′′ , col ′′ ) = Canonize(P ′ , col ′ ), where (P ′ , col ′ ) is a well-coloured a ′ 2 -b path with l − 1 different colours. Let ω ′′ = ColoursSignsW(P ′′ , col ′′ ) be the colours-signs word of P ′′ . By the induction hypothesis, (P ′′ , col ′′ ) = CanonPath(ω ′′ , a ′ 2 , |P ′′ |). Moreover, for constructing path P c we started from a along µ c1 following sign s 1 until we reached the first vertex b ′ 1 adjacent to vertex a ′ 2 of µ c2 , and concatenated it with the canonical a ′ 2 -b path (P ′′ , col ′′ ), as in the definition of the CanonPath function. Therefore, path (P c , col c ) is canonical for the triple (ω c , a, |P c |). It remains to show that the length of P c is at most |P | + 2(l − 1). We proceed again by induction on l. The property is true if l = 1 since P c = P . Otherwise, for l ≥ 2, recall that (P c , col c ) = (P [a, b ′ 1 ], monochr c1 ) ⊕ (P ′′ , col ′′ ) where (P ′′ , col ′′ ) = Canonize(P ′ , col ′ ) and (P ′ , col ′ ) = (µ c2 [a ′ 2 , b 2 ], monochr c2 ) ⊙ (P [b 2 , b], col) is a well-coloured a ′ 2 -b path with l − 1 different colours (by lines 6 and 7 of Algorithm 1). Now we show that: We recall that in the well-coloured path (P, col), b 1 denotes the last vertex on P such that col(b 1 ) = c 1 and a 2 the first vertex on P such that col(a 2 ) = c 2 . In particular (see Figure 3), while P can be described by Therefore, in order to prove Inequality 2, we need to show that | no matter in which order the vertices a ′ 2 , a 2 and b 2 appear on µ c2 . These observations prove Inequality 3, which proves Inequality 2.
▶ Corollary 14. Let G be a graph whose vertices are covered by k shortest paths. For any vertex a of G and any fixed distance D, there are at most g(k) vertices at distance D from a, where: For any fixed vertex a and fixed length L, the number of vertices that can be reached from a through a canonical well-coloured path of length L is upper bounded by (k−i)! , the number of colours-signs words, by Lemma 6. Moreover for each vertex b, by Corollary 13, there exists a canonical well-coloured a-b path P such that |P | ≤ dist(a, b) + 2(k − 1). Therefore the number of vertices at a fixed distance D from a in G is at most (2k − 1) · h(k). Indeed, vertex b is uniquely identified by a, the colours-signs word of the well-coloured path P , and the quantity |P | − dist (a, b). The latter has 2k − 1 possible values, from 0 to 2(k − 1), which completes the proof. ◀ In order to complete the proof of Theorem 1 (in the case where the k paths cover all vertices of the graph) and show that the pathwidth of G is at most 2 · g(k), we apply Lemma 4 for K = g(k), and the conclusion follows.

Algorithmic consequences
Problem Strong Geodetic Set with Terminals is known to be NP-complete by [8]. By a simple reduction, so is Isometric Path Cover with Terminals.
We now prove Theorem 2 and Corollary 3. Recall that, for simplicity, we assume that our input graph is connected, but all results easily extend to disconnected graphs. We first show that problem Isometric Path Cover with Terminals is FPT when parameterized by k, the number of pairs of terminals. As a first consequence, so is problem Strong Geodetic Set with Terminals, a special case of Isometric Path Cover with Terminals with k 2 pairs of terminals. (Both problems are NP-complete, by [8] and Appendix 15.) Corollary 3 follows immediately, since for both Isometric Path Cover and Strong Geodetic Set it suffices to try all possible sets of terminals and use the FPT algorithms for the versions with terminals.
Let us focus on Isometric Path Cover with Terminals, with parameter k, input G and the k pairs of terminals (s 1 , t 1 ), . . . , (s k , t k ). We can assume that the treewidth of the input graph is upper bounded by a function of k, as stated in Theorem 1, and that we have in the input a tree decomposition of such width. Indeed recall that Theorem 1 does not only provide a combinatorial bound on the pathwidth of YES-instances, but also a simple, BFS-algorithm for computing the suitable path decompositions (which is also, as stated in Section 2, a tree decomposition of the same width). If the algorithm fails to find a path decomposition of small width, we can directly conclude that our input graph is a NO-instance. Therefore, we can use the classical Monadic Second-Order Logic of graphs (MSOL 2 ) tools on bounded treewidth graphs. MSOL 2 includes the logical connectives ∨, ∧, ¬, ⇔, ⇒, variables for vertices, edges, sets of vertices, and sets of edges, the quantifiers ∀ and ∃ that can be applied to these variables, and five binary relations: adj(u, v), where u and v are vertex variables and the interpretation is that u and v are adjacent; inc(v, e), where v is a vertex variable and e is an edge variable and the interpretation is that v is incident to e; v ∈ V ′ , where v is a vertex variable and V ′ is a vertex set variable; the similar e ∈ E ′ on edge variable e and edge set variable E ′ , and eventually equality of two variables of the same nature.
By a celebrated theorem of Courcelle [6], any problem expressible in MSOL 2 can be solved in time f (tw) · n time on bounded treewidth graphs, if a tree decomposition of the input graph is also given. Function f depends on the formula (hence, on the problem).
Courcelle's theorem extends in several ways to optimization problems, and slightly larger classes of formulae, e.g., allowing to identify a fixed number of terminal vertices, as we shall detail later. Here we will refer to [3], one of the (alternative) proofs of Courcelle's theorem, with some extensions.
As noted for example in [3], MSOL 2 allows to express properties as Connected(V ′ , E ′ ) where V ′ is a vertex set variable and E ′ is an edge set variable and the property is true if and only if (V ′ , E ′ ) is a connected subgraph of G. Also let Cover(V 1 , . . . , V k ) express the fact that vertex subsets V 1 , . . . , V k cover all vertices of the graph, by simply stating that This allows us to express Isometric Path Cover with Terminals as an optimization MSOL 2 problem, called an EMS-problem in [3].
Let φ(E 1 , E 2 , . . . , E k ) be the formula on edge sets E 1 , . . . , E k expressing the property that there exist k connected subgraphs (V 1 , E 1 ), . . . , (V k , E k ) of G such that the sets V 1 , . . . , V k cover all vertices of G, and graph (V i , E i ) contains terminals s i , t i , for all 1 ≤ i ≤ k. More formally: Consider now the optimization version of this problem, where the goal is to find edge sets E 1 , E 2 , . . . , E k satisfying φ(E 1 , E 2 , . . . , E k ) and minimizing |E 1 | + |E 2 | + · · · + |E k |. Let OptCover denote this optimum. By Theorem 5.6 in [3], this problem can be solved in linear time on bounded treewidth graphs. More precisely, Arnborg et al. [3] call such problems "EMS linear extremum problems", in the sense that they correspond to linear optimization functions over the sizes of set variables, when these variables satisfy an MSOL 2 formula over labelled graphs with a fixed number of labels (here we consider each terminal vertex labeled with a different label). In contemporary terms, the problem is FPT parameterized by treewidth plus the number of terminals, and the running time is linear in n.
We now conclude by observing that our input is a YES-instance of Isometric Path Cover with Terminals if and only if OptCover = dist(s 1 , t 1 ) + dist(s 2 , t 2 ) + . . . dist(s k , t k ). Indeed if there exist the required shortest s i -t i paths P 1 , . . . , P k covering the vertex set of the whole graph, then their edge sets E 1 , . . . , E k provide a solution for our optimization problem whose objective is the sum of the lengths of the paths. Conversely, for any of the k connected subgraphs (V i , E i ) of G such that s i , t i ∈ V i , we have |E i | ≥ dist(s i , t i ). Therefore by simply checking if OptCover corresponds to the sum of the distances between pairs of terminals, we decide whether the input satisfies Isometric Path Cover with Terminals. Altogether, this problem is FPT parameterized by k, which concludes the proof of Theorem 2.
As mentioned in the introduction, the same techniques extend to variants where the covering paths are required to be edge-disjoint or vertex-disjoint, by simply adding disjointness conditions in the MSOL 2 formula φ.

Conclusion
We have shown that graphs that can be covered by k shortest paths have their pathwidth upper-bounded by a function of k. Our bound is super-exponential, 2 Θ(k log k) . The first natural open question is whether this upper bound can be improved to something smaller, perhaps even polynomial in k? Such an improvement cannot rely on path decompositions based on the layers of an arbitrary BFS, since we have examples (see Figure 4) where the

Figure 4
A graph that can be edge-covered with k shortest paths and with 2 k vertices at distance 2 k − 1 from a. Therefore, a path decomposition obtained by a BFS from vertex a has width exponential in k. Nevertheless, one can easily prove that this graph has pathwidth at most k. same layer contains 2 k vertices. Nevertheless, we leave as an open question whether graphs whose vertices (or edges) can be covered by k shortest paths have treewidth at most a polynomial in k.
Observe that the approach does not generalize to coverings with few induced paths, since grids have arbitrarily large treewidth but are edge-coverable by four induced paths.
On the algorithmic side, we have proved that problems Isometric Path Cover with Terminals and Strong Geodetic Set with Terminals are FPT parameterized by the number of terminals. This directly entails that problems Isometric Path Cover and Strong Geodetic Set are in XP with respect to the same parameter, by simply enumerating all possible pairs (respectively, sets) of terminals. An exciting open question is whether these two problems are FPT. By Theorem 1, this is equivalent to asking if the problems are FPT when parameterized by the solution size (i.e., number of paths/terminals) + pathwidth. (Indeed, if k is the number of terminals, Theorem 1 ensures that either the pathwidth pw of the input graph is upper bounded by a function f (k), or we can directly reject the input for being a NO-instance. Therefore, if one of the problems is FPT parameterized by k + pw, we obtain an FPT algorithm parameterized by k as follows. The algorithm checks that pw ≤ f (k) as in Theorem 1, by a simple breadth-first search from an arbitrary vertex. If the assertion is false, the algorithm rejects. Otherwise it simply remains to apply the algorithm parameterized by k + pw on parameter k + f (k).) Nevertheless, the answer to the question whether these problems are FPT for parameter k + pw seems non-trivial. At least, while many optimization problems are FPT when parameterized by treewidth/pathwidth, several problems including constraints on distances remain W [1]-hard even when parameterized by such structural parameters, plus solution size. We can cite recent hardness results for d-Scattered Set [13], whose goal is to find a large set of vertices at pairwise distance at least d or, even closer to our problems, Geodetic set [14], where one aims to find a small set of terminals of the input graph such that the set of all shortest paths between every pair of terminals covers the graph.