1 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, where one asks to cover the vertices of an input graph using a prescribed number of paths. The corresponding packing problem is Disjoint Paths (here, given a set of pairs of terminal vertices of a graph , one asks whether there are vertexdisjoint paths in , each joining two paired terminals). Disjoint Paths is a fundamental problem and a precursor to the field of parameterized complexity due to the celebrated fixedparameter tractable algorithm devised by Robertson and Seymour [RS95] for the parameter “number of paths”. We recall that in the field of parameterized algorithms and complexity, one studies parameterized problems, whose input comes together with a parameter . A parameterized problem is said to be FPT (fixedparameter tractable) if it can be solved in time , for some computable function . If the problem can be solved in time , it belongs to class class ; see, e.g., [CFK+15] for more details.
In this paper, we will not consider arbitrary paths, but shortest paths, which are fundamental for many applications. In the problem Disjoint Shortest Paths, given a graph and pairs of terminals, one asks whether contains vertexdisjoint shortest paths pairwise connecting the pairs of terminals. This problem was introduced in [EilamTzoreff98] and recently shown to be polynomialtime solvable for every fixed by an XP algorithm [Lochet21]. The problem Isometric Path Cover with Terminals, which we define as follows, is the covering counterpart of Disjoint Shortest Paths.
Isometric Path Cover with Terminals Input: A graph , and pairs of vertices called terminals. Question: Does there exist a set of shortest paths, the th path being an  shortest path, such that each vertex of belongs to at least one of the paths? 
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 [IPC] in the context of the Cops and Robbers game on graphs (see also [AF84]).
Isometric Path Cover Input: A graph , and an integer . Question: Does there exist a set of shortest paths, such that each vertex of 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 terminals, and one asks to find 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 [DIT21, BrazilMaster].
Strong Geodetic Set with Terminals Input: A graph , and a set of vertices of called terminals. Question: Does there exist a set of shortest paths, each path joining a distinct pair of terminals, such that each vertex of belongs to at least one of the paths? 
The variant where the terminals are not given in the input was defined in [SGS] as follows.
Strong Geodetic Set Input: A graph , and an integer . Question: Does there exist a set of terminals and a set of shortest paths, each path joining a distinct pair of terminals, such that each vertex of belongs to at least one of the paths? 
The complexity of these problems has been studied in the literature. Isometric Path Cover is NPhard, even for chordal graphs, on which the problem can be approximated within a constant factor [FloManuscrit]. It was proven to be polynomialtime solvable on block graphs [IPCblock]. It is shown in [DIT21] that Strong Geodetic Set with Terminals is NPhard. In [BrazilMaster], it is shown that this holds even for bipartite graphs of maximum degree 4 or diameter 6, however Strong Geodetic Set with Terminals is polynomialtime solvable on split graphs, graphs of diameter 2, block graphs, and cactus graphs. There is a straightforward reduction from Strong Geodetic Set with Terminals to Isometric Path Cover with Terminals, implying that the latter problem is NPComplete. We describe such a reduction in Appendix A for the sake of completeness.
Finally, Strong Geodetic Set is known to be NPhard [SGS], even for bipartite graphs, chordal graphs, graphs of diameter and cobipartite graphs [BrazilMaster] as well as for subcubic graphs of arbitrary girth [DIT21]. However it is polynomialtime solvable on outerplanar graphs [M20], cactus graphs, block graph and threshold graphs [BrazilMaster].
All these problems can also be studied in their edgecovering 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 [MKXAT17].
Our results
Our main combinatorial theorem is as follows (see Section 2 for the definition of pathwidth).
Theorem 1.
Let be a graph whose edge set can be covered by at most shortest paths. Then the pathwidth of is at most , for function .
If is such that its vertex set can be covered by at most shortest paths, then the pathwidth of is at most .
We actually show that in such graphs , given an arbitrary vertex and an integer , the number of vertices at distance exactly from is upperbounded by a function of , that does not depend on the size of the input graph. It follows that a very simple lineartime algorithm based on a breadthfirst search provides a path decomposition whose width is upperbounded by the aforementioned function of . The complexity of the algorithm itself does not depend on .
Besides the combinatorial bounds, we employ the celebrated theorem of Courcelle [Courcelle90], stating that problems expressible in Monadic SecondOrder Logic () can be solved in linear time for graphs of bounded treewidth (and thus, of bounded pathwidth). More precisely, we reduce problem Isometric Path Cover with Terminals to an optimization problem expressible in . The result can also be obtained by dynamic programming but we prefer the general logicbased framework for further extensions. The running time is linear in , the number of vertices of the graph, but superexponential in the parameter . Together with Theorem 1, this implies the following.
Theorem 2.
Problems Isometric Path Cover with Terminals and Strong Geodetic Set with Terminals are FPT when parameterized by the number of terminals.
Moreover, this also entails the following.
Corollary 1.
Problems Isometric Path Cover and Strong Geodetic Set are in XP when parameterized by the number of terminals.
Thanks to the flexibility of Monadic SecondOrder Logic, our algorithmic results easily extend to the edgecovering versions of our problems, and to variants where we require the paths to be edgedisjoint, or vertexdisjoint (as studied in [M20a]).
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 shortest paths, then the tools are extended to vertexcoverings in the next section. Algorithmic consequences (Theorem 2) are derived in Section 5, and we conclude with some open questions.
2 Preliminaries and notations
Paths and concatenation operators and
We refer to [DiestelB] for usual notations on graphs. For simplicity, we consider that our input graph is connected, though all our combinatorial and algorithmic results extend to nonconnected graphs. As usually denotes the neighborhood of vertex .
A path of graph is a sequence of distinct vertices such that for each , is an edge of the graph. We also say that is a  path. Note that our paths are simple, they do not use twice a same vertex. We denote by the vertices of path , and by its edges. Given two vertices , we denote by the subpath of between and . Moreover we let denote the length of path , that is, the number of its edges. The distance between two vertices and in is denoted and corresponds to the length of a shortest  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  path, we think of it as being directed from to .
Given two paths and of such that is an edge of , we define the concatenation operator whose result is . In particular, .
We define similarly the glueing operator between two paths and by . Note that in this case .
Path decompositions through breadthfirst search
A path decomposition of is a sequence of vertex subsets of , called bags, such that for every edge there is at least one bag containing both endpoints, and for every vertex , the bags containing form a continuous subsequence of . The width of is , and the pathwidth of is the minimum width over all path decompositions of .
The treewidth of graph is defined similarly (see e.g. [DiestelB]), using socalled tree decomposition; for our purpose, we only need to know that for any graph , , in particular any path decomposition is also a tree decomposition of same width. We also need the following folklore lemma on path decompositions.
Lemma 1.
Let be a graph, be a vertex of and be an upper bound on the number of vertices of at distance exactly from , for any integer .
Then, . Moreover, a path decomposition of width can be computed in linear time, by breadthfirst search.
Proof.
Let be the eccentricity of vertex (i.e., ). For any with we denote by the set of vertices at distance exactly from , i.e. the layers of a breadthfirst on starting at . Observe that, by taking as bags the unions of pairs of consecutive layers, , and by ordering them according to , we obtain a path decomposition of . Indeed for each edge both endpoints are in a same layer or in two consecutive layers, thus will appear in a same bag. For each vertex , it appears in at most two bags: if then is in bags and (or one bag if or ), and these bags appear consecutively in the decomposition. Since each layer has at most vertices, the width of this decomposition is at most . ∎
3 Warmup: edgecovering with shortest paths
As a warmup, we start by proving Theorem 1 in the case when graph is edgecoverable by shortest paths. In this case, there is a simple and elegant encoding of shortest paths leading to the desired result; the case of vertexcovering, more technical, will be studied in the next section.
In this section, denotes a graph whose edge set is coverable by shortest paths. Let us fix such a set of paths , and call them the base paths of . 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 with an arbitrary direction. E.g., assuming that the vertices of are numbered from to , the direction of path is from its smallest towards its largest endvertex. A (directed) subpath of is given a positive sign if it follows the direction of , otherwise it is given a negative sign . For each edge of , let be the set of all values such that is an edge of .
Good colourings
Let be an  path of , from vertex to vertex . A colouring of is a function assigning to each edge of the path one of its colours . The colouring of is said to be good if, for any colour , the set of edges using this colour form a connected subpath of . (Since our paths are simple, this condition entails that .) A pair formed by a path together with a good colouring is called wellcoloured.
Operator defined in Section 2 naturally extends to coloured paths. Given a coloured path , we simply denote by its restriction to a subpath of . Finally, we define for any path and any colour the function . Hence all edges of the coloured path have colour .
With these notations, any wellcoloured  path with colours appearing in this order can be written as for some vertices . In full words, are the monochromatic subpaths of , coloured .
Lemma 2 (Good colouring lemma).
For any pair of vertices and of , there exists a wellcoloured  path such that is a shortest  path.
We will simply call a wellcoloured shortest  path.
Proof.
Among all shortest  paths, choose one that admits a colouring with a minimum number of monochromatic subpaths. Let be this path, and the corresponding colouring. Assume by contradiction that the colouring is not good. Then there exist three edges , and , appearing in this order, such that . Assume w.l.o.g. that the vertices appear in the order , from to . Let . Therefore and are on the same base path . Let be the path obtained from by replacing by . First, is no longer than , since is a shortest possible  path of graph . Second, in we can colour all edges of with colour , and keep all other colours unchanged. Hence has strictly fewer monochromatic subpaths than — a contradiction. ∎
Let be a wellcoloured  path, with colours in this order. Recall that each monochromatic subpath of , of colour , induces a sign on the corresponding base path (positive if has the same direction as , negative otherwise). Therefore, we can define the colourssigns word on the alphabet , corresponding to the colours and signs of the monochromatic subpaths of , according to the ordering in which these subpaths appear from to . Observe that such words have at most letters on an alphabet of size . Therefore the number of different words is upper bounded by a function of :
Lemma 3.
The number of possible colourssigns words, over all wellcoloured paths of , is upper bounded by .
Proof.
We claim that the number of colourssigns words of letters is upper bounded by . Observe that the colours form a word of length , on an alphabet of size , without repetition. The number of such words is (e.g., by choosing letters among the possible ones, and applying all possible permutations). Since each letter also has a sign in , we multiply this quantity by , and the conclusion follows by summing over all possible values of . ∎
The following crucial lemma implies that, given a start vertex , a distance and a colourssigns word , there is at most one vertex at distance from , such that the wellcoloured shortest  path respects word . This will allow to upper bound the number of vertices at distance from .
Lemma 4 (Colourssigns encoding).
Consider two vertices and at same distance from some vertex of . Let be a wellcoloured shortest  path and be a wellcoloured shortest  path. If , then .
Proof.
We proceed by induction on the number of letters of the word . Let us denote it by .
Let (resp. ) be the maximal subpath of (resp. ) of colour starting from . Assume w.l.o.g. that is at least as long as . Since both are subpaths of , starting from and having the same sign w.r.t. , we actually have that is contained in , in particular is between and in and in .
Observe that, if word has only one letter, and , thus they are all of the same length. Since they are of the same sign w.r.t. , this implies that , which proves the base case of our induction.
Assume now that has letters and that the lemma is true for words of length .
Consider first the case when and have the same length. Then is also the first vertex of the subpaths of colour of both and . Then and are wellcoloured shortest paths of the same length, and have the same colourssigns word , with letters. Hence the property follows by the induction hypothesis.
We now handle the second and last case, when is strictly longer than . Let be the last vertex of the subpath coloured in . In particular, and are all vertices of .
Let us make an easy but crucial observation: on , vertex is between and . To prove this claim, note that in path , vertices , and appear in this order (as observed in the beginning of the proof), and by construction appears between and . Therefore appear in this order on , which is a shortest path. Hence . Since the three vertices are all on the shortest path , they must appear in this order on the latter. Consequently, induces the same sign on as .
In particular, in the path , we can replace the first subpath coloured by , coloured , without changing the total length. We obtain the wellcoloured shortest  path . Its colourssigns word is , the same as for the shortest  path . Moreover, the two paths have the same length, , hence by the induction hypothesis we have , which proves our lemma. ∎
Corollary 2.
For any vertex of and any integer , there are at most vertices at distance exactly from .
Proof.
4 Vertexcovering with shortest paths
In this section, denotes a graph whose vertices can be covered by shortest paths . As before we endow each base path 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 vertexcolourings. Again, for any pair of vertices and , there is a wellcoloured shortest path joining them (Lemma 5), which defines a colourssigns word. But we shall see that now (unlike in the simpler case of edgecoverings), we may have two distinct vertices and at a same distance from , and wellcoloured shortest  and  paths with a same colourssigns word. More efforts will be needed to recover a (slightly larger) upper bound on the number of vertices at distance from (Corollary 4).
Good colourings
For each vertex of , let denote the set of indices (colours) such that is a vertex of . Let be an  path of , from vertex to vertex . A colouring of is a function assigning to each vertex of one of its colours . A coloured path is a pair . The colouring of is said to be good if, for any colour , the subgraph induced by the set of vertices using this colour forms a connected subpath of (which implies that ). A coloured path where is a good colouring is called wellcoloured.
Operators and naturally extend to (vertex) coloured paths, with the precaution that is defined only when their common vertex , the last of and first of , satisfies . Given a coloured path , we again denote by its restriction to a subpath of . For each colour , let now denote the monochromatic colouring of with colour .
With these notations, any wellcoloured  path with colours is of the form for some vertices , as in Figure 2.
Like in the previous section, we have:
Lemma 5.
For any pair of vertices and of , there exists a wellcoloured shortest  path.
Proof.
Among all shortest  paths, choose one that admits a colouring with a minimum number of monochromatic subpaths. Let be such a coloured path. Assume for a contradiction that the colouring is not good. Then there exist three vertices and , appearing in this order in such that . Therefore and are on a same base path . Let be the path obtained from by replacing by . Notice that is no longer than , since is a shortest  path of graph . Moreover, in we can colour all vertices of with colour , and keep all other colours unchanged. Hence has strictly fewer monochromatic subpaths than — a contradiction. ∎
Colourssigns word
Let be a wellcoloured  path; we recall that we see it as being directed from to . As in Section 3, each monochromatic subpath of , say of colour , induces a sign ( or ) depending on its direction w.r.t. , if has at least two vertices. If has a unique vertex, we assign to it sign . Therefore, we can again define the colourssigns word on the alphabet , corresponding to the colours and signs of the monochromatic subpaths of according to the ordering in which these subpaths appear from to .
In the case of edgecovering, we had the elegant statement of Lemma 4, by which, given a vertex , a colourssigns word and a distance , there is a unique vertex at distance such that the wellcoloured shortest  path corresponds to this word. Unfortunately, this does not extend to vertexcovering: Figure 1 presents two distinct vertices and located at a same distance from vertex , together with a wellcoloured shortest  path and a wellcoloured shortest  path . These coloured paths starting from have the same colourssigns word and the same length, but this does not imply that their endpoints are equal.
Canonical wellcoloured paths
In order to obtain a situation somewhat similar to the case of edgecovering, we define a canonical representation of wellcoloured paths (see Figure 2 for an example). Given a colourssigns word with no repetition of colours, a start vertex and a length , we define a unique wellcoloured path starting from , of the prescribed length and having the colourssigns word , as follows:

If , let be the vertex at distance of on the path w.r.t. . Then :

Otherwise, let be the first vertex of starting from w.r.t. having a neighbour in . Among the vertices of adjacent to , choose to be the one that appears first in , according to its direction. We let:
(1)
Note that the path might not exist, e.g. if, in the base case of the construction, or the subpath of starting from and following sign is shorter than or, in the second step, vertex does not exist, or exceeds .
Observation 1.
Given a colourssigns word , a vertex and a length , if the path exists, then it is wellcoloured. Moreover, this path is unique and satisfies .
Proof.
Notice first that, by construction, we have and 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 wellcoloured. The uniqueness of path comes from the deterministic choices made during the algorithm, which concludes the proof. ∎
Definition 1 (canonical wellcoloured path).
A wellcoloured  path is called canonical if .
To obtain a result similar to Lemma 4, we provide an algorithm that takes as input a wellcoloured  path , the corresponding good colouring with colours, and that computes a canonical wellcoloured  path whose length is upperbounded by (see Algorithm 1 and Lemma 6). As before, let be the colourssigns word of and for each , let (resp. ) denote the first (resp. last) vertex of coloured . Informally, the algorithm recursively computes a coloured path as follows: if , we let . Otherwise, we consider as the first vertex of (hence, of starting from following sign ) having a neighbour in (line 1). As in the definition of the function, we choose the neighbour of to be the vertex of that appears first on this path, according to its direction, among the neighbours of (line 1). We next replace by (see line 1 and Figure 3), and then reapply the transformation on the new path starting from (line 1).
Lemma 6 (canonization of wellcoloured paths).
Given a wellcoloured  path (, with a colourssigns word of letters, the result of is a canonical wellcoloured  path of length at most .
Proof.
Denote and let be its colourssigns word. We first claim that is a canonical wellcoloured path, i.e. equal to (Definition 1). In order to prove the claim we proceed by induction on the number of colours of . The property is true if has a unique colour, since in this (base) case, and (line 1 of Algorithm 1).
Otherwise, by induction, is formed by concatenated with , where is a wellcoloured  path with different colours. Let be the colourssigns word of . By the induction hypothesis, . Moreover, for constructing path we started from along following sign until we reached the first vertex adjacent to vertex of , and concatenated it with the canonical  path , as in the definition of the function. Therefore, path is canonical for the triple .
It remains to show that the length of is at most . We proceed again by induction on . The property is true if since . Otherwise, for , recall that where and is a wellcoloured  path with different colours (by lines 1 and 1 of Algorithm 1). Now we show that:
(2) 
We recall that in the wellcoloured path , denotes the last vertex on such that and the first vertex on such that . In particular (see Figure 3),
while can be described by
Therefore, in order to prove Inequality 2, we need to show that
(3) 
Observe that , otherwise would not be a shortest  path since the  path would be of length , thus shorter. Next, observe that no matter in which order the vertices and appear on . These observations prove Inequality 3, which proves Inequality 2.
Inequality 2 entails that . By the induction hypothesis on , since uses colours, we have that . Thus
Now since we have that . Plugging this into the previous inequality we have , which completes the proof of our lemma. ∎
Corollary 3 (canonical representation).
Given two vertices and , there exists a canonical wellcoloured  path such that .
Proof.
In particular, Lemma 6 implies the following.
Corollary 4.
Let be a graph whose vertices are covered by shortest paths. For any vertex of and any fixed distance , there are at most vertices at distance from , where:
Proof.
For any fixed vertex and fixed length , the number of vertices that can be reached from through a canonical wellcoloured path of length is upper bounded by , the number of colourssigns words, by Lemma 3. Moreover for each vertex , by Corollary 3, there exists a canonical wellcoloured  path such that . Therefore the number of vertices at a fixed distance from in is at most . Indeed, vertex is uniquely identified by , the colourssigns word of the wellcoloured path , and the quantity . The latter has