An Improved Algorithm for Computing All the Best Swap Edges of a Tree Spanner

A treeσ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\sigma $$\end{document}-spanner of a positively real-weighted n-vertex and m-edge undirected graph G is a spanning tree T of G which approximately preserves (i.e., up to a multiplicative stretch factorσ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\sigma $$\end{document}) distances in G. Tree spanners with provably good stretch factors find applications in communication networks, distributed systems, and network design. However, finding an optimal or even a good tree spanner is a very hard computational task. Thus, if one has to face a transient edge failure in T, the overall effort that has to be afforded to rebuild a new tree spanner (i.e., computational costs, set-up of new links, updating of the routing tables, etc.) can be rather prohibitive. To circumvent this drawback, an effective alternative is that of associating with each tree edge a best possible (in terms of resulting stretch) swap edge—a well-established approach in the literature for several other tree topologies. Correspondingly, the problem of computing all the best swap edges of a tree spanner is a challenging algorithmic problem, since solving it efficiently means to exploit the structure of shortest paths not only in G, but also in all the scenarios in which an edge of T has failed. For this problem we provide a very efficient solution, running in O(n2log4n)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(n^2 \log ^4 n)$$\end{document} time, which drastically improves (almost by a quadratic factor in n in dense graphs) on the previous known best result.


Introduction
The problem of computing all the best swap edges (ABSE) of a tree has a long and rich algorithmic tradition. Basically, let G = (V (G), E(G), w) be an n-vertex and m-edge 2-edgeconnected undirected graph, with edge-weight function w : E(G) → R + , and assume we are given a spanning tree T of G, which was computed by addressing some criterion (i.e., objective function) φ. Then, the problem is that of computing a BSE for every edge e ∈ E(T ), namely an edge f ∈ E(G) \ E(T ) such that the swap tree T e/f obtained by swapping e with f in T optimizes some objective function φ out of all possible swap trees. Quite reasonably, the function φ must be related (if not coinciding at all) with φ. The first immediate motivation for studying an ABSE problem comes from the edge fault-tolerance setting -a commonly accepted framework. Broadly speaking, the algorithmic question here is to design sparse subgraphs that guarantee a proper level of functionality even in the presence of an edge failure. In such a context, the rationale of an ABSE-based solution is the following: operations are normally performed on a (possibly optimal) spanning

Our result
In this paper, we present a new algorithm that solves the ABSE-TS problem in O(n 2 log 4 n) time and O(n 2 + m log 2 n) space. Thus, our solution improves on the running time of both the algorithms provided in [3], for weighted and unweighted graphs, respectively, whenever m = Ω(n log 3 n). Most remarkably, for dense weighted graphs, the improvement is almost quadratic in n.
To put into focus our result, it is worth noticing that, as observed in [10], the estimation of the stretch of the swap tree induced by a single swap edge f for a given failing edge e, would in principle ask for the evaluation of the stretch of O(m) relevant pairs of nodes in G, namely the endvertices of all the non-tree edges that may serve as swap edge for e besides f . And in fact, a critical edge for f is the one whose endvertices maximize such a stretch out of these non-tree edges, and two swap edges will be essentially compared on the basis of their stretch w.r.t. their critical edge. This is basically the reason why both previous approaches take Ω(m 2 ) time. Thus, to avoid such a bottleneck, we drastically reduce, on the one hand, the number of candidate best swap edges, and on the other hand, the number of potential critical edges that need to be checked. More precisely, for each of the n − 1 considered edges in T , we succeed in reducing to O(n log n) the number of best swap edge candidates, and for each one of them we just need to check O(log 2 n) possible critical edges. The key ingredients to reach such a goal are the following: A centroid decomposition of T , which consists of a log-depth hierarchical decomposition of the vertices in T ; a careful use of such a decomposition, combined with a set of preprocessing steps that associate various information with the tree nodes, allows us to reduce the number of candidate BSEs and of their corresponding candidate critical edges. As far as we know, this is the first time that such a decomposition is used to solve an ABSE problem, and we believe it will possibly be useful in other contexts as well. The second ingredient is given by the dynamic maintenance of the upper envelopes of a set of linear functions. Each of these functions is associated with a non-tree edge, and whenever the failure of a given tree edge is considered, it expresses the stretch such a non-tree edge induces w.r.t. a variable candidate BSE. This way, when we have to find a critical edge for a given candidate BSE f , we have to select the maximum out of all the functions once they are evaluated in f . In geometric terms, this translates into the maintenance of the upper envelope of a set of functions, with the additional complication that, for consistency reasons, this set of functions must be suitably partitioned into groups according to the underlying centroid decomposition, and moreover these groups are dynamic, since they depend on the currently considered tree edge.

Related work
The research on tree spanners is very active, also due to the strong relationship with the huge literature on spanners, where distances in G are approximately preserved through a sparse spanning subgraph. As mentioned before, finding an optimal tree spanner is a quite hard problem. More precisely, on weighted graphs, if G does not admit a tree 1-spanner (i.e., a spanning tree with σ = 1, which can be established in polynomial time [9]), then the problem is not approximable within any constant factor better than 2, unless P=NP [16]. In terms of approximability, no non-trivial upper bounds are known, except for the O(n)-approximation factor returned by a minimum spanning tree (MST) of G. If G is unweighted, things go slightly better. More precisely, in this case the problem becomes O(log n)-approximable, while unless P=NP, the problem is not approximable within an additive term of o(n) [11]. Moreover, the corresponding decision problem of establishing whether G admits a tree spanner with stretch σ is NP-complete for every fixed σ ≥ 4 (for σ = 2 it is polynomial-time solvable [9], while for σ = 3 the problem is open). Finally, it is known that constant-stretch tree spanners can be found for several special classes of (unweighted) graphs, like strongly chordal, interval, and permutation graphs (see [7] and the references therein).
Concerning the problem of swapping in spanning trees, this has received a significant attention from the algorithmic community. There is indeed a line of papers that address ABSE problems starting from different types of spanning trees. Just to mention a few, besides the MST, we recall the minimum diameter spanning tree (MDST), the minimum routing-cost spanning tree (MRCST), and the single-source shortest-path tree (SPT). Concerning the MDST, a best swap is instead an edge minimizing the diameter of the swap tree [13,17], and the best solution runs in O(m log α(m, n)) time [6]. Regarding the MRCST, a best swap is clearly an edge minimizing the all-to-all routing cost of the swap tree [23], and the fastest solution for solving this problem has a running time of O m2 O(α(n,n)) log 2 n [5]. Concerning the SPT, the most prominent swap criteria are those aiming to minimize either the maximum or the average distance from the root, and the corresponding ABSE problems can be addressed in O(m log α(m, n)) time [6] and O(m α(n, n) log 2 n) time [21],respectively. Recently,in [4], the authors proposed two new criteria for swapping in a SPT, which are in a sense related with this paper, namely the minimization of the maximum and the average stretch factor from the root, for which they proposed an efficient O(mn + n 2 log n) and O(mn log α(m, n)) time solution, respectively.
Finally, for the sake of completeness, we mention that for the related concept of average tree σ-spanners, where the focus is on the average stretch w.r.t. all node-to-node distances, it was shown that every graph admits an average tree O(1)-spanner [1].

Preliminary definitions
Let G = (V (G), E(G), w) be a 2-edge-connected, edge-weighted, and undirected graph with cost function w : E(G) → R + . We denote by n and m the number of vertices and edges of G, respectively. If X ⊆ V (G), let E(X) be the set of edges incident to at least one vertex in X. When X = {v}, we may write E(v) instead of E({v}). Given an edge e ∈ E(G), we will denote by G − e the graph obtained from G by removing edge e. Similarly, given a vertex v ∈ V (G), we will denote by G − v the graph obtained from G by removing vertex v and all its incident edges. Given an edge e ∈ E(T ), we let S(e) be the set of all the swap edges for e, i.e., all edges in E(G) \ {e} whose endpoints lie in two different connected components of T − e. We also define S(e, X) = S(e) ∩ E(X), and S(e, X, Y ) = S(e) ∩ E(X) ∩ E(Y ). When X = {v}, we will simply write S (e, v) in lieu of S (e, {v}). For any e ∈ E(T ) and f ∈ S(e), let T e/f denote the swap tree obtained from T by replacing e with f . Given two vertices x, y ∈ V (G), we denote by d G (x, y) the distance between x and y in G. We define the stretch factor of the pair (x, y) w.r.t. G and T as σ G (T, x, y) = d T (x,y) d G (x,y) . Accordingly, the stretch factor σ G (T ) of T w.r.t. G is defined as σ G (T ) = max x,y∈V (G) σ G (T, x, y).
In the sequel, in order to solve the ABSE-TS problem, we will show how to efficiently find a BSE for every edge e of a tree spanner T of G.

High-level description of the algorithm
It is useful to consider the tree T as rooted at any fixed vertex, and to assume, w.l.o.g., that T is binary. Indeed, if T is not binary, then it is possible, by using standard techniques, to transform G and T into an equivalent graph G and a corresponding binary spanning tree T , with |V (G )| = Θ(n) and |E(G )| = Θ(m), and such that a BSE for any edge of T compute a v-BSE f for e and the corresponding stretch factor; // This takes O(log 4 n) time by using T and the dynamic maintenance of the upper envelopes associated with the swap edges, as shown in Section 3 return f * as BSE for e and continue with the next phase.
is univocally associated with a BSE for a corresponding edge of T . This transformation requires linear time and it is sketched in Appendix A for the sake of completeness. As a preprocessing step, we compute a centroid decomposition of T . A centroid of an n-vertex tree is a vertex whose removal splits T into subtrees of size at most n/2 [15]. A centroid decomposition of T can be computed in O(n log n) time, and can be represented by a tree T of height O(log n), whose nodes are actually subtrees of T . T is recursively defined as follows: the root of T is T . Then, let τ be a node of T (i.e., a subtree of T ) such that τ contains more than one vertex, and let c be a centroid of τ . Since T is binary, the forest τ − c contains at most 3 trees, that we call τ 1 c , τ 2 c , and τ 3 c (if τ − c generates less than 3 subtrees, we allow some τ i c to be the empty tree). Moreover, let τ 0 c be the subtree of T containing the sole vertex c. Then, τ will have in T a child for each of the subtrees τ i c , i = 0, . . . , 3 (see Figure 1 (a)). Since a centroid on a n-vertex tree can be found in linear time, the whole procedure requires O(n log n) time, and it is easy to see that the height of T is O(log n).
Our solution (see Algorithm ABSE-TS) works in n − 1 phases, one for each tree edge as considered in preorder w.r.t. T , and at the end of each phase returns a BSE for that edge. Let e ∈ E(T ) be the currently considered edge, and let U e (resp. D e ) be the set of vertices that belong to the connected component of T − e that contains (resp. does not contain) the root of T . We break down each of these phases into O(n) additional sub-phases: when edge e is failing, we consider all the vertices in U e and, for each such vertex v, we solve a restricted version of the ABSE-TS problem where we compute: (i) a v-restricted best swap edge (v-BSE for short), i.e., an edge f ∈ arg min f ∈S (e,v) σ G−e (T e/f ), and (ii) the corresponding stretch factor σ G−e (T e/f ). To simplify handling of special cases, whenever S(e, v) = ∅, we assume that f = ⊥ and that σ G−e (T e/f ) = +∞. As we will see in the rest of the paper, the core of our algorithm is exactly the efficient computation of these v-BSEs and of their stretch factors. This is done trough a clever selection of a small set of candidate v-BSEs, as we will discuss in more detail in the next section. Once all the v-BSEs for e are computed, a BSE for e can be found as the one minimizing the associated stretch factor.

Computing efficiently a v-BSE
To show how a v-BSE for e can be computed efficiently, we need some preliminary definitions: The subtree T is represented by the three gray triangles along with the vertex c. f is a swap edge for e that minimizes w(f ) + dT (u, c), and g is its corresponding critical edge. The (c, y)-tree of T is drawn in bold. Notice that f and g do not need to be incident to T .

Definition 3 (Best Cut Edge
Then, we will make use of the following property, which was given in [3]: Let us first provide a high-level description of how we compute a v-BCE (i.e., a v-BSE) for e. The algorithm will compute O(log n) v-BCE candidates, the best of which will be a v-BCE for e. Informally speaking, each candidate f will be a swap edge close to the centroid of a certain subtree Λ of T . Depending on the position of a critical edge for f , the algorithm will recurse on a subtree of Λ and it will look for the next candidate. Thanks to the centroid decomposition of T , the number of recursions/candidates will then be O(log n).
The key ingredient for the correctness of our algorithm is the next lemma. Given a subtree T of T , a vertex c ∈ V ( T ), and a vertex y ∈ V (T ), consider the first vertex z of the unique path from y to c in T that also belongs to V ( T ). The (c, y)−tree of T is defined as follows: (1) if z = c, then it is the empty tree; otherwise (2) it is the tree of the forest T − c that contains z. Then, the following holds (see also Figure 1  Proof. Suppose that f is not a v-BCE for e, we will show that no swap edge f = (v, u ) ∈ S (e, v) with u ∈ V (T ) can be a v-BCE for e. Indeed: where we used the fact that d T (u , y) = d T (u , c) + d T (c, y) as either u = c or u and y are in two different connected components of T − c.
Lemma 4 allows us to design a recursive algorithm for computing a v-BCE for e, whose key steps are highlighted in Procedure FindBCE (notice that v and e are fixed). More precisely, Compute an edge f = (v, u) ∈ arg min (v,u)∈S (e,v)

Proof. First of all, notice that Step 4 can be performed in O(1) time, after a O(log n)
preprocessing time in which we mark all the nodes of T on the path between the leaf of T containing the lower vertex of e (which clearly belongs to D e ) and the root of T . Then, we only need to bound the depth of the recursion of the call FindBCE(T ). Observe that each time Procedure FindBCE(Λ) recursively invokes itself on a tree Λ , we have that Λ is a child of Λ in T . The claim follows since the height of T is O(log n).

Actually, the time to execute
Step 7 is O(log n), after a preprocessing time and space of O(n 2 ), by making use of top-trees [2]. Due to space limitations, this result is postponed to the appendix. On the other hand, Procedure FindCritical will require O(log 3 n) time and O(m log 2 n) space, as we will show in the next two subsections.

Computing a critical edge for f
We will compute O(log 2 n) critical edge candidates for f and we will show that a critical edge for f will be one of them. More precisely, we look at O(log n) subtrees of the centroid decomposition T and, for each such subtree Λ, we will consider O(log n) subtrees Ψ to find a critical edge candidate having one endpoint in Ψ and the other in Λ. The choice of the O(log 2 n) pairs of trees is guided by the position of f , while the computation of a candidate for a given pair (Ψ, Λ) is the core of the procedure and is described in the next subsection.
Definition 7 ((Ψ, Λ)-Critical Edge). Given a failing edge e and a swap edge f = (v, u) ∈ S (e, v), and given two trees Ψ, Λ of the centroid decomposition T , a (Ψ, Λ)-critical edge for f is an edge g = (x, y) ∈ arg max g ∈S(e,V (Ψ)∩Ue,V (Λ)∩De) φ(f, g ). When Ψ = T we will refer to a (Ψ, Λ)-critical edge as a Λ-critical edge. (e, v) and let Λ be a tree of the centroid decomposition T such that u ∈ V (Λ). Procedure FindCritical returns a Λ-critical edge for f , when edge e fails (such an edge always exists as f has one endpoint in U e and the other in V (Λ) ∩ D e ). Notice that the call FindCritical(f, T ) in Procedure FindBCE computes a critical edge for f , since a T -critical edge for f is actually a critical edge for f . Procedure FindCritical uses as a subroutine Procedure FindCriticalCandidate(f , Ψ, Λ), which for the sake of clarity will be described in the next subsection. For the moment, it suffices to know that FindCriticalCandidate receives three inputs, i.e., edge f = (v, u) and two subtrees Ψ, Λ of the centroid decomposition T such that v ∈ Ψ and, either u ∈ V (Λ) or Λ is the tree containing the sole vertex u, and it returns a (Ψ, Λ)-critical edge for f . If no such edge exists, then FindCriticalCandidate returns ⊥ and we assume that φ(f, ⊥) = −∞.
Lemma 8. Let f = (v, u) ∈ S (e, v), and let Λ be a tree of the centroid decomposition T such that u ∈ V (Λ). Procedure FindCritical(f, Λ) returns a Λ-critical edge for f .

Proof. The proof is by induction on the cardinality of V (Λ).
If |V (Λ)| = 1, then the only vertex in Λ must be u and Procedure FindCritical invokes Procedure FindCriticalCandidate(f, T, Λ). Hence, assuming such a procedure is correct, it returns a (T, Λ)-critical edge, i.e., a Λ-critical edge. If |V (Λ)| > 1 then we distinguish two cases, depending on the position of the centroid c of Λ.
If c ∈ D e it is sufficient to notice that a Λ-critical edge for f must be incident to a tree τ i c for some i = 0, 1, 2, 3. Let j be the unique index in {0, 1, 2, 3} such that u ∈ V (τ j c ). If j = i then, assuming Procedure FindCriticalCandidate is correct, it returns a (T, Λ)-critical edge g 1 (and hence a Λ-critical edge) for f . Procedure FindCritical then returns either g 1 or another edge g such that φ(f, g) = φ(f, g 1 ). If j = i, the algorithm is recursively invoked and, since |V (τ i c )| < |V (Λ)| we know, by the induction hypothesis, that it correctly returns a τ i c -critical edge for f , which is also Λ-critical edge for f .
If c ∈ U e , then we know that there is at most one τ i c containing one or more vertices in D e (as otherwise the vertices in V (Λ) ∩ D e would be disconnected in Λ, a contradiction). Moreover, since u ∈ V (Λ) ∩ D e , there is exactly one such tree τ i c , namely τ j c . The algorithm recursively invokes itself on τ j c and, since |V (τ j c )| < |V (Λ)|, we know, by induction hypothesis, that it returns a τ j c -critical edge for f , which is also Λ-critical edge for f .

Lemma 9.
Procedure FindCritical(f, Λ) requires O(Γ FCC · log n) time, where Γ FCC is the time required by an invocation of Procedure FindCriticalCandidate.
Proof. Notice that Procedure FindCritical performs exactly one recursive invocation for each vertex of the tree T on the unique path between the root of T and u in T . The claim follows since the height of T is O(log n).
In the next subsection, we show that Γ FCC = O(log 2 n), and then we give our final result.

Procedure FindCriticalCandidate
In this subsection, we describe the core of the procedure that computes a critical edge for f . Let us first describe informally the main idea of this part. Let b ∈ U e and c ∈ D e , and consider any two edges f = (v, u), g = (x, y) ∈ S(e) such that b (resp. c) is on the unique path from x to v (resp. from y to u) in T (see Figure 2). It turns out that the stretch factor of any f w.r.t. a given g can be though as a linear function Φ b,c,g (t) = α b,c (g) · t + β b,c (g), where α b,c (g) and β b,c (g) only depend on g. More precisely, we will have that φ(f, g) = Φ b,c,g (t b,c (f )), for a suitable value t b,c (f ) which only depends on f . Hence, whenever we look for a critical edge for f , we can ask for a corresponding function Φ b,c,g (t) with maximum value on t b,c (f ). Since we do not know a priori the edge f for which we need to compute a critical edge, we will maintain this information as the upper envelope of a suitable set of functions. Let us make this idea more precise. . Notice how, once b and c are fixed, t b,c (f ) only depends on f while α b,c (g) and β b,c (g) only depend on g. Let Φ b,c,g (t) = α b,c (g) · t + β b,c (g).
Lemma 11. Let f = (v, u) ∈ S (e, v). Let b ∈ U e and c ∈ D e . Let X (resp. Y ) be a set of vertices x ∈ U e (resp. y ∈ D e ) such that vertex b (resp. c) is on the unique path from x to v (resp. from y to u) in T . For every g ∈ S(e, X, Y ) we have φ(f, g) = Φ b,c,g (t b,c (f )).
Definition 12 (Parent centroid). Let τ be a tree of the centroid decomposition T . The parent centroid of τ is the centroid of the parent of τ in T . f is a swap edge for e, Ψ and Λ are two trees of the centroid decomposition, and b and c are their corresponding parent centroids. g is a potential (Ψ, Λ)-critical edge for f . Notice that the unique path from x to v (resp. from y to u) passes through b (resp. c).
Lemma 11 is instrumental to proving the following (see Figure 2): (e, v), and let Ψ, Λ be two trees of the centroid decomposition of T such that the following conditions hold: Let b (resp. c) be the parent centroid of Ψ (resp. Λ), and assume that b ∈ U e (resp. c ∈ D e ). Then, an edge g is a (Ψ, Λ)-critical edge for f if and only if Proof. First of all we show the following property of the centroid decomposition T : let p, q ∈ V (T ), and suppose that the unique path in T between the leaf nodes associated with p and q contains a node whose corresponding centroid is z. Then, the unique path between p and q in T contains z. Indeed, if z is either p or q, the property is trivially true. On the other hand, suppose that z ∈ {p, q}, and let τ be the subtree of T associated with z in T . Then, let τ i z be the child subtree of τ containing p. Observe that q is not in τ i z . Moreover, by construction, each path from a node of τ i z , and in particular from p, to any node outside τ i z , and in particular to q, must pass through z.
We now prove the claim. If V (Ψ) = {v} (resp. V (Λ) = {u}) then it follows from Lemma 11 by choosing X = {v} and Y = V (Λ) ∩ D e (resp. X = V (Ψ) ∩ U e and Y = {u}). The complementary case is the one in which v ∈ V (Ψ) and u ∈ V (Λ). Consider the vertices v and b (resp. u and c) in T and notice that v (resp. u) cannot be an ancestor of b (resp. c). Indeed, if that were the case, then the subtree of T induced by the vertices in V (Ψ) (resp. V (Λ)) would contain b (resp. c) contradicting the hypothesis. Hence, the path from any vertex in V (Ψ) to v (resp. V (Λ) to u) traverses b (resp. c) in T and therefore the same holds in T . The claim follows by invoking Lemma 11 with X = V (Ψ) ∩ U e and Y = V (Λ) ∩ D e .
Lemma 13 allows us to design a recursive procedure to compute a (Ψ, Λ)-critical edge for f (see Procedure FindCriticalCandidate). To this aim we will make use of a data structure Q e that, for each edge f ∈ S(e), and for each pair of trees Ψ, Λ of the centroid decomposition, can perform a query operation that we name Q e (f, Ψ, Λ). This query reports an edge whose function Φ b,c,g is in UE F (t b,c (f )) where b and c are the parent centroids of Ψ and Λ, respectively, and Next two lemmas show the correctness and the running time of the procedure: Lemma 14. Let be given an edge f = (v, u) ∈ S (e, v) and two trees Ψ, Λ of the centroid decomposition such that: (i) v ∈ V (Ψ), and (ii) u ∈ V (Λ) or V (Λ) = {u}. Then, Procedure FindCriticalCandidate(f, Ψ, Λ) computes a (Ψ, Λ)-critical edge for f .

Proof.
First of all notice that if V (Λ) ∩ D e = ∅, then the algorithm correctly returns ⊥. We now prove the claim by induction on |V (Ψ)|. If |V (Ψ)| = 1, then the only vertex in Ψ must be v and Procedure FindCriticalCandidate queries Q e for Q e (f, Ψ, Λ). By Lemma 13, the returned edge is a (Ψ, Λ)-critical edge for f . If |V (Ψ)| > 1 then we distinguish two cases, depending on the position of the centroid b of Ψ. If b ∈ U e it is sufficient to notice

A Reducing the degree of T
Here we show a linear time reduction that transforms G and a rooted spanning tree T of G into an equivalent graph G = (V (G ), E(G ), w) and a corresponding binary spanning tree T such that |V (G )| = Θ(n) and |E(G )| = Θ(m). Initially, G , w , and T coincide with G, w, and T , respectively. We iteratively search for a vertex u in T that has 3 or more children, and we lower its degree. Let v 1 , . . . , v h , with h ≥ 3, be the children of u. We remove all the edges {(u, v i ) : 1 ≤ i ≤ h} from both G and T , then we add to both G and T a binary tree whose root coincides with u, and that has exactly h leaves x 1 , . . . , x h . We assign weight w (e) = 0 to all the edges e of this tree. Finally, we add to G and T an edge (x i , v i ) for each 1 ≤ i ≤ h, and we set w (x i , v i ) = w (u, v i ). An example of such a transformation is shown in Figure 3. Figure 3 Reducing the degree of vertices in G: on the left side, the tree T (solid edges) embedded in G, on the right side the superimposition of the binary tree to T in order to get a maximum degree of 3. Solid edges in the gray area have weight 0, while the weight of (xi, vi) is w(u, vi).
Clearly, |V (G )| = O(|V (G)|), |E(G )| = O(|E(G)|), and, moreover, the computation of G and T requires linear time. Now, observe that, for every a, b ∈ V (G), it holds that d T e/f (a, b) = d T e/f (a, b). Furthermore, for every edge e = (u, v i ) of T , f is a swap edge for e in T iff f is a swap edge for the edge (z, v i ) in T , where z is the parent of v i in T . As a consequence, we can conclude that, for every edge e = (u, v i ) of T , f ∈ S(e) is a BSE for e w.r.t. T iff f is a BSE for the edge (z, v i ) w.r.t. T , where z is the parent of v i in T .

B Selecting edge f in Step 7 of Procedure FindBCE(Λ)
In this section we show how to efficiently find an edge f = (v, u) ∈ S(e) minimizing w(f ) + d T (u, c), where c is a vertex in D e , as Procedure FindBCE requires. We will show how this problem can be solved by using top-trees [2]. A top-tree is a dynamic data structure that maintains a (weighted) forest F of trees under link (i.e., edge-insertion) and cut (i.e., edge-deletion) operations. Moreover, some of the vertices of F can be marked and the top-tree is able to perform closest marked vertex (CMV, for short) queries, i.e., it can report the marked vertex that is closest to a given vertex z. A top-tree on n vertices can be built in linear time and each of all the aforementioned operations requires O(log n) time.
We maintain a top-tree Υ v of size O(n) for each vertex v ∈ V (T ), and so we use a total of O(n 2 ) space. Each of these top-trees is the tree T augmented with some additional marked  (e, v), and (b) the corresponding top-tree Υv. The black vertices of Υv are the same of the tree T . For each u ∈ V (T ) such that f = (v, u) ∈ S (e, v), Υv contains an additional vertex u (shown as a white square), and a corresponding edge (u, u) with weight w(f ).
vertices. More precisely, for each v ∈ V (T ) and for each edge f = (v, u) ∈ E(G) \ E(T ) we add to Υ v a marked vertex u and the edge (u, u) with a weight of w(f ) (see Figure 4).
Whenever we are finding a v-BSE for e and we need to find the edge f minimizing w(f ) + d T (u, c) we do the following: (i) we cut the edge e from Υ v , (ii) we perform a CMV query on Υ v to find the closest marked vertex u to c, if any, (iii) we undo the cut operation by linking the endpoints of e in Υ v , and finally (iv) we return the edge (v, u) (or ⊥ if no u has been found).
Lemma 17. Let e ∈ E(T ) be a failing edge and let c ∈ D e . An edge f = (v, u) ∈ S (e, v) minimizing w(f ) + d T (u, c) can be found in O(log n) time. Moreover, all the top-trees Υ v can be initialized in O(n 2 ) time.
Proof. Each of the n top-trees Υ v can be built in time O(n) by explicitly considering all the edges in E(v) (notice that Υ v contains at most 2n vertices as there can be at most one marked vertex per vertex in V (T )).
As for the time complexity of finding edge f , it immediately follows from the fact that we perform a constant number of link, cut, and CMV query operations, hence we only need to argue about correctness.
Notice that after we cut edge e from Υ v in step (i), the tree T of Υ v containing c has exactly one (distinct) marked vertex u for each edge (u, v) ∈ S (e, v). The claim follows as, by construction, the distance from c to u in T is d T (c, u) = d T (c, u) + d T (u, u) = d T (c, u) + w(f ).

C Dynamic maintenance of the upper envelopes
Procedure FindCriticalCandidate needs the auxiliary structure Q e . Explicitly building such a structure for each edge e would be too expensive. In the remaining of this section we show how all the Q e 's can be built in O(m log 4 n) time and O(m log 2 n) space. The idea is to exploit the order in which failing edges are considered, so as to reuse previously computed information to build Q e . We implement Q e as a dictionary that allows us to add, delete, and search for elements in O(log n) time per operation. Each element of Q e is a data structure that can store a set F of linear functions and is able (i) to dynamically add/remove a function to/from F in O(log |F|) time, (ii) given t ∈ R, to report a function in UE F (t) in O(log |F|) amortized time [8].