Improved Distance Sensitivity Oracles with Subcubic Preprocessing Time
IImproved Distance Sensitivity Oracles withSubcubic Preprocessing Time
Hanlin Ren
Institute for Interdisciplinary Information Sciences, Tsinghua University, Beijing, [email protected]
Abstract
We consider the problem of building
Distance Sensitivity Oracles (DSOs). Given a directed graph G = ( V, E ) with edge weights in { , , . . . , M } , we need to preprocess it into a data structure, andanswer the following queries: given vertices u, v ∈ V and a failed vertex or edge f ∈ ( V ∪ E ), outputthe length of the shortest path from u to v that does not go through f . Our main result is a simpleDSO with ˜ O ( n . M ) preprocessing time and O (1) query time. Moreover, if the input graph isundirected, the preprocessing time can be improved to ˜ O ( n . M ). The preprocessing algorithmis randomized with correct probability ≥ − /n C , for a constant C that can be made arbitrarilylarge. Previously, there is a DSO with ˜ O ( n . M ) preprocessing time and polylog( n ) query time[Chechik and Cohen, STOC’20].At the core of our DSO is the following observation from [Bernstein and Karger, STOC’09]: ifthere is a DSO with preprocessing time P and query time Q , then we can construct a DSO withpreprocessing time P + ˜ O ( n ) · Q and query time O (1). (Here ˜ O ( · ) hides polylog( n ) factors.) Theory of computation → Shortest paths; Theory of computation → Data structures design and analysis
Keywords and phrases
Graph theory, Shortest paths, Distance sensitivity oracles
Related Version
There is a paper with the same title accepted to ESA’20 [17]. Compared to thatversion, here we use a new argument dealing with non-unique shortest paths, thus improve thepreprocessing time from ˜ O ( n . M ) to ˜ O ( n . M ). We also extend our argument to edgefailures, instead of only vertex failures as in [17]. Acknowledgements
I would like to thank Zihao Li for introducing this problem to me, Ran Duanand Yong Gu for helpful discussions, and Ce Jin for helpful comments that improve the presentationof this paper. I would also like to thank Hongxun Wu for reading and commenting on an early draftversion of this paper, and pointing out the issue with non-unique shortest paths. I am also gratefulto the anonymous referees of ESA for their helpful comments that improve the presentation of thispaper, and for suggesting me to consider the more general case that edge weights may be negative.(Unfortunately, I am not aware of any easy way to generalize our results to handle negative edgeweights.)
Suppose we are given a directed graph G = ( V, E ), and we want to build a data structurethat, given any two vertices u, v ∈ V and a failure f , which is either a failed vertex or afailed edge, outputs the length of the shortest path from u to v that does not go through f .Such a data structure is called a Distance Sensitivity Oracle (or DSO for short).The problem of constructing DSOs is motivated by the fact that real-life networks oftensuffer from failures. Suppose we have a network with n nodes and m (directed) links, and wewant to send a package from a node u to another node v . Normally, it suffices to computethe shortest path from u to v . However, if some node or link f in this network fails, thenour path cannot use f , and our task becomes to find the shortest path from u to v that doesnot go through f . Usually, there is only a very small number of failures. In this paper, weconsider the simplest case, in which there is only one failed node or link. a r X i v : . [ c s . D S ] J u l Improved DSOs with Subcubic Preprocessing Time
The problem of constructing a DSO is well-studied: Demetrescu et al. [6] showed thatgiven a directed graph G = ( V, E ), there is a DSO which occupies O ( n log n ) space, andcan answer a query in O (1) time. Duan and Zhang [9] improved the space complexity to O ( n ), which is optimal for dense graphs (i.e. m = Θ( n )).Unfortunately, the oracle in [6] requires a large preprocessing time ( O ( mn + n log n )).In real-life applications, the preprocessing time of the DSO is also very important. Bernsteinand Karger [2, 3] improved this time bound to ˜ O ( mn ). Note that the All-Pairs ShortestPaths (APSP) problem, which only asks the distances between each pair of vertices u, v , isconjectured to require mn − o (1) time to solve [14]. Since we can solve the APSP problem byusing a DSO, the preprocessing time ˜ O ( mn ) is optimal in this sense.However, if the edge weights are small positive integers (that do not exceed M ), then theAPSP problem can be solved in ˜ O ( n . M ) time [22] , which is significantly faster than O ( mn ) for dense graphs with small weights (e.g. M = O (1)). Thus it might be possible toobtain better results than [3] in the regime of small integer edge weights. Weimann and Yuster[21] showed that for any constant α ∈ (0 , O ( n − α + ω M ) time.Here ω < . O ( n α ), which is superlinear . Later, Grandoni and Williams [13] showedthat for every constant α ∈ [0 , O ( n ω +1 / M + n ω + α (4 − ω ) M )time, which answers each query in ˜ O ( n − α ) time.Recently, in an independent work, Chechik and Cohen [4] showed that a DSO withpolylog( n ) query time can be constructed in ˜ O ( M n . ) time, achieving both subcubicpreprocessing time and polylogarithmic query time. The space complexity for their DSO is˜ O ( n . ). In this work, we show improved and simplified constructions of DSOs. We start with anobservation. (cid:73)
Observation 1.1 (informal) . If we have a DSO with preprocessing time P and query time Q , then we can build a DSO with preprocessing time P + ˜ O ( n ) · Q and query time O (1) . For α = 0 .
2, the oracle in [13] already achieves ˜ O ( n . M ) preprocessing time and O ( n . ) query time. Observation 1.1 implies that this query time can be brought down to O (1).Observation 1.1 can be proved by a close inspection of [3]: The algorithm in [3] forconstructing a DSO picks ˜ O ( n ) carefully chosen queries ( u, v, x ), such that the answers ofall these queries can be computed in ˜ O ( mn ) time. Then from these answers, we can easilycompute a DSO with O (1) query time. If, instead of computing these answers in ˜ O ( mn ) time,we use the given DSO to answer these queries, the preprocessing time becomes P + ˜ O ( n ) · Q .Our main result is a simple construction of DSOs with preprocessing time ˜ O ( n . M )and query time O (1). If the input graph is undirected, we can achieve a better preprocessingtime of ˜ O ( n . M ). (cid:73) Theorem 1.2.
We can construct a DSO with ˜ O ( n . M ) preprocessing time and O (1) query time. Moreover, if the input graph is undirected , then we can construct a DSO with [22] only claims a time bound of ˜ O ( n . M ); the time bound ˜ O ( n . M ) is calculated using improvedtime bounds for rectangular matrix multiplication, see [12]. . Ren 3 ˜ O ( n (3+ ω ) / M ) = ˜ O ( n . M ) preprocessing time and O (1) query time. The constructionalgorithms are randomized and yield valid DSOs w.h.p. Compared to previous constructions of DSOs, our results have better dependence on n ,and is conceptually simpler. Also, the space complexity of our DSO is ˜ O ( n ), which is betterthan [4]. However, one drawback of our construction is that it cannot handle negative edgeweights. (The preprocessing and query time bounds stated above for [4, 13, 21] still holdwhen the edge weights are integers in [ − M, M ].)
A subtle technical issue is that the shortest paths in G between some vertex pairs may notbe unique. Normally, if we perturb every edge weight by a small random value, then we canensure that shortest paths are unique w.h.p. by the isolation lemma [16, 20]. However, thesubcubic-time algorithms for APSP [18, 19, 22] depend crucially on the assumption that edgeweights are small integers, so we cannot perform the random perturbation.Fortunately, there is another elegant way of breaking ties, described in Section 3.4 of [5],that is suitable for our propose. We arbitrarily assign a linear order ≺ over the edges of G .(For example, we index the edges by distinct numbers in { , , . . . , m } , and define e ≺ e ifthe index of e is smaller than the index of e .) For a path p , define the bottleneck edge of p as the smallest edge (w.r.t. ≺ ) in p . Let G be a subgraph of G (think of G = G or G is G with some vertex or edge removed), define w G ( u, v ) as the largest (w.r.t. ≺ ) edge w ∈ G such that there is a shortest path in G from u to v whose bottleneck edge is w . Define ρ G ( u, v ) to be the following path: If u = v , then ρ G ( u, v ) is the empty path; otherwise,suppose w G ( u, v ) is an edge from u ? to v ? , then ρ G ( u, v ) is the concatenation of ρ G ( u, u ? ), w G ( u, v ) and ρ G ( v ? , v ). Note that ρ G ( u, v ) is always well-defined: we can define ρ G ( u, v )inductively, in non-decreasing order of the distance from u to v .We list a few properties of this tie-breaking method in the following theorem. (cid:73) Theorem 1.3.
The following properties of ρ G ( u, v ) are true: (Property a) For every u , v ∈ ρ G ( u, v ) such that u appears before v , the portion of u (cid:32) v in ρ G ( u, v ) coincides with the path ρ G ( u , v ) . (Property b) Let G be a subgraph of G , suppose ρ G ( u, v ) is completely contained in G , then ρ G ( u, v ) = ρ G ( u, v ) . For every vertex u ∈ V , we can compute the collection of paths ρ G ( v, u ) for every v ∈ V .By (Property a), these paths form a tree rooted at u , and we say this tree is the incomingshortest path tree rooted at u , denoted as T in ( u ). Similarly we can define the outgoing shortestpath trees rooted at each vertex, denoted as T out ( u ). The advantage of this tie-breakingmethod is: (cid:73) Theorem 1.4 ([8]) . Given a subgraph G , the incoming and outgoing shortest path trees T in ( u ) and T out ( u ) for each vertex u can be computed in ˜ O ( n (3+ ω ) / M / ) time. For completeness we will prove Theorem 1.3 and 1.4 in Appendix A.
We mainly stick to the notation used in [7], namely: We say that an event happens with high probability (w.h.p.), if it happens with probability 1 − /n C ,for some constant C that can be made arbitrarily large. Improved DSOs with Subcubic Preprocessing Time If p is a path, then | p | denotes the number of edges in it, and k p k denotes its length(i.e. the total weight of its edges).Let u, v ∈ V , we denote uv = ρ G ( u, v ), i.e. the unique shortest path from u to v in theoriginal graph. For a vertex or edge failure f , we denote uv (cid:5) f = ρ G − f ( u, v ), where G − f is the subgraph of G obtained by removing the failure f . Note that if f is not inthe original path uv , then by (Property b), uv (cid:5) f = uv .Let p be a path from u to v . For two vertices a, b ∈ p such that a appears earlier than b , we say the interval p [ a, b ] is the subpath from a to b , and p ( a, b ) is the path p [ a, b ]without its endpoints ( a and b ). If the path p is known in the context, then we may omit p and simply write [ a, b ] or ( a, b ). (Property a) implies that, if p is the path uv (or uv (cid:5) f resp.), then p [ a, b ] is the path ab (or ab (cid:5) f resp).We define MM ( n , n , n ) as the complexity of multiplying an n × n matrix andan n × n matrix. Let a, b, c be real numbers, we define ω ( a, b, c ) be the infimum overall real numbers α such that MM ( n a , n b , n c ) = O ( n α ). For any real number r , we have ω (1 , , r ) = ω (1 , r,
1) = ω ( r, ,
1) [15], and we denote ω ( r ) = ω (1 , , r ).We also need the following adaptation of Zwick’s APSP algorithm [22] (see also [13,Corollary 3.1]): (cid:73) Theorem 1.5.
Given a directed graph G = ( V, E ) with edge weights in { , , . . . , M } , andan integer r , we can compute the distances between every pair of nodes whose shortest pathuses at most r edges, in ˜ O ( rM · MM ( n, n/r, n )) time. Proof Sketch.
We simply run the first d log / r e iterations of the algorithm rand-short-path in [22]. The correctness of this algorithm is guaranteed by [22, Lemma 4.2]. (cid:74) ˜ O ( n . M ) Time
In this section, we prove Theorem 1.2. (cid:73)
Theorem 1.2.
We can construct a DSO with ˜ O ( n . M ) preprocessing time and O (1) query time. Moreover, if the input graph is undirected , then we can construct a DSO with ˜ O ( n (3+ ω ) / M ) = ˜ O ( n . M ) preprocessing time and O (1) query time. The constructionalgorithms are randomized and yield valid DSOs w.h.p. Given an integer r and a graph G = ( V, E ), we define an r -truncated DSO to be a datastructure that, when given a query ( u, v, f ), outputs the value min {k uv (cid:5) f k , r } . In otherwords, an r -truncated DSO is a DSO which only needs to be correct when the path uv (cid:5) f has length at most r . If this length is greater than r , it outputs r instead.Inspired by Zwick’s APSP algorithm [22], our main idea is to compute an r -truncatedDSO for every r = (3 / i . Our strategies for small r and large r are completely different.When r is small, the sampling approach in [13, 21] already suffices. Fix a particular query( u, v, f ), we assume that f is a vertex failure, and k uv (cid:5) f k ≤ r . In particular, since theedge weights are positive, there are at most r + 1 vertices in the path uv (cid:5) f . Suppose wesample a graph by discarding each vertex w.p. 1 /r . With probability Ω(1 /r ), the resultinggraph would “capture” this query in the sense that f is not in it but uv (cid:5) f is completelyincluded in it. Therefore, if we take ˜ O ( r ) independent samples, and compute APSP for eachsampled subgraph, we can deal with every vertex-failure query w.h.p. If f is an edge failure,we simply discard every edge (instead of vertex) in every subgraph w.p. 1 /r , and we can stilldeal with every edge-failure query w.h.p. . Ren 5 For large r , our idea is to compute a (3 / r -truncated DSO from an r -truncated DSO.More precisely, given an r -truncated DSO with O (1) query time, we can compute a (3 / r -truncated DSO with ˜ O ( M n/r ) query time. First we sample a bridging set (see [22]) H ofsize ˜ O ( M n/r ). Let ( u, v, f ) be a query such that r ≤ k uv (cid:5) f k ≤ (3 / r , then w.h.p. thereis a “bridging vertex” h ∈ H such that h is on the path uv (cid:5) f , and both of the queries( u, h, f ) and ( h, v, f ) are captured by the r -truncated DSO. If we iterate through H , wecan answer the query ( u, v, f ) in ˜ O ( M n/r ) time. Then we use an “ r -truncated” version ofObservation 1.1 to transform this (3 / r -truncated DSO into a new one with O (1) querytime. r is Small Let ˜ r = d Cr ln n e , where C is a large enough constant. We independently sample 2˜ r graphs G e , G e , . . . , G e ˜ r and G v , G v , . . . , G v ˜ r . (The superscripts e and v stand for “edge” and “vertex”respectively.) Each graph is sampled as follows:The vertex set of each G e i is equal to the original vertex set V , and the edge set of each G e i is sampled by including every edge independently w.p. 1 − /r .The vertex set of each G v i is sampled by including every vertex independently w.p. 1 − /r ,and the graph G v i is the induced subgraph of G on vertices V ( G v i ).Then, for each 1 ≤ i ≤ ˜ r , we compute all-pairs shortest paths of the graph G e i and G v i , butwe only compute the shortest paths that use at most r edges. By Theorem 1.5, this step canbe done in ˜ O ( rM · MM ( n, n/r, n )) time for each graph. Alternatively, if the input graph isundirected, then this step can be done in ˜ O ( M n ω ) time [18, 19] for each graph.Consider a query ( u, v, f ), suppose f is a vertex failure, and assume that k uv (cid:5) f k ≤ r .Let 1 ≤ i ≤ ˜ r , we say i is good for the query ( u, v, f ), if both of the following hold.The graph G v i does not contain f .The graph G v i contains the entire path uv (cid:5) f .For every i (1 ≤ i ≤ ˜ r ), the probability that i is good for the particular query ( u, v, f ) isat least(1 /r ) · (1 − /r ) r +1 ≥ / r (if r ≥ u, v, f ), where f is a vertex failure, we iterate through all i ’s such that f V ( G v i ), and take the smallest value among the distances from u to v in these graphs G v i .With high probability, there are only ˜ O (1) valid i ’s such that f G v i , and we can preprocessthis set of i ’s for every f ∈ V . Therefore the query time is ˜ O (1).The algorithm succeeds at a query ( u, v, f ) if there is an i that is good for ( u, v, f ). Sincethe G i ’s are independent, the probability that there is an i good for ( u, v, f ) is at least1 − (1 − / r ) ˜ r ≥ − /n C . By a union bound over all n triples of possible queries ( u, v, f ), it follows that our datastructure is correct w.p. at least 1 − /n C − , which is a high probability.If f is an edge failure, we look at the graphs G e i instead of G v i . We say i is good if thegraph G e i does not contain f but contains the entire path uv (cid:5) f . Again, if we fix ( u, v, f ),then the probability that a particular i is good is at least 1 / Ω( r ), so w.h.p. there is some i that is good for ( u, v, f ). By a union bound over all O ( n ) triples ( u, v, f ), our data structureis still correct w.h.p.In conclusion, there is an r -truncated DSO with ˜ O (1) query time, whose preprocessingtime is ˜ O (˜ r · rM · MM ( n, n/r, n )) for directed graphs, and ˜ O (˜ r · M n ω ) for undirected graphs. Improved DSOs with Subcubic Preprocessing Time
We need the following observation (“ r -truncated” version of Observation 1.1), which roughlystates that given an r -truncated DSO with preprocessing time P and query time Q , we canbuild an r -truncated DSO with preprocessing time P + ˜ O ( n ) · Q and query time O (1). Moreformally, we have: (cid:73) Observation 2.1.
Let r be an integer, G = ( V, E ) be an input graph, and D be an arbitrary r -truncated DSO. We can construct Fast( D ) , which is an r -truncated DSO with O (1) querytime and a preprocessing algorithm as follows.It first computes the distance matrix of G , and the (incoming and outgoing) shortest pathtrees rooted at each vertex.Then it invokes the preprocessing algorithm of D on the input graph G .At last, it makes ˜ O ( n ) queries to D , and spends ˜ O ( n ) additional time to finish thepreprocessing algorithm. We emphasize the following technical details that are not reflected in the informalstatement of Observation 1.1. First, we need to compute the distance matrix and shortestpath trees of G (henceforth the “APSP data” of G ) before using D . We can compute theAPSP data using Theorem 1.4. Second, the preprocessing algorithm of D is called onlyonce , and on the same graph G (on which we have already computed the APSP data). Thereason that the second detail is important is: Suppose we have another routine that given an r -truncated DSO D , constructs Extend( D ) which is a (3 / r -truncated DSO with a possiblylarge query time. Then given an 1-truncated DSO D start , we can construct a (normal) DSOas follows: D final = Fast(Extend(Fast(Extend( . . . Extend( D start ))))) | {z } O (log n ) times . However, even if the preprocessing algorithm of Fast( D ) invokes the preprocessing al-gorithm of D twice , the preprocessing algorithm of D final would invoke a polynomial times the preprocessing algorithm of D start , which is too many. In contrast, if the preprocessingalgorithm of both Fast( D ) and Extend( D ) only invokes the preprocessing algorithm of D once, then the preprocessing algorithm of D final would also invoke the preprocessing algorithmof D start only once, which is okay. r is Large Suppose we have an r -truncated DSO D , which has preprocessing time P and query time O (1). We show how to construct a (3 / r -truncated DSO, which we name as Extend( D ),with preprocessing time P + O ( n ) and query time ˜ O ( nM/r ). This is done by the followingbridging set argument.Let P be the set of paths uv (cid:5) f , for every u, v ∈ V and f ∈ ( V ∪ E ) such that r ≤ k uv (cid:5) f k < (3 / r . This corresponds to the paths that D cannot deal with, butExtend( D ) has to output the correct answer. Let p = uv (cid:5) f ∈ P , mid ( p ) be the set of vertices y ∈ p such that k p [ u, y ] k < r and k p [ y, v ] k < r . (See Figure 1.) For every y ∈ mid ( p ), as p [ u, y ] = uy (cid:5) f and p [ y, v ] = yv (cid:5) f , it follows that D can find k uy (cid:5) f k and k yv (cid:5) f k correctly.Moreover, | mid ( p ) | ≥ r/ M . . Ren 7 r r | {z } mid ( p ) u y v v Figure 1
Example of a path p = uv (cid:5) f . If we can find a vertex y ∈ mid ( p ), then we can use D tocompute k uy (cid:5) f k and k yv (cid:5) f k , thus to compute the length of p . Fix a large enough constant C , the preprocessing algorithm of Extend( D ) is as follows:We preprocess D , and then randomly sample a set H of vertices, where every vertex v ∈ V isin H with probability min { , CM ln n/r } independently. We have | H | = ˜ O ( nM/r ) w.h.p.Fix u, v ∈ V and f ∈ ( V ∪ E ), suppose p = uv (cid:5) f and r ≤ k p k < (3 / r . Then theprobability that H hits mid ( p ) (i.e. H ∩ mid ( p ) = ∅ ) is at least1 − (1 − CM ln n/r ) r/ M ≥ − /n C . By a union bound over O ( n ) paths in P , it follows that w.h.p. H hits mid ( p ) for everypath p ∈ P .The query algorithm for Extend( D ) is as follows: Given a query ( u, v, f ), if D ( u, v, f ) < r ,then we output D ( u, v, f ); otherwise we outputmin (cid:26) (3 / r, min h ∈ H, D ( u,h,f ) 1] be a constant that we pick later, and r = n a . We first compute the APSP datausing Theorem 1.4, which costs ˜ O ( n (3+ ω ) / M / ) time and will not be the bottleneck. Then weinvoke Section 2.1 to build an r -truncated DSO for r = n a , which costs ˜ O ( r M · MM ( n, n/r, n ))time for directed graphs or ˜ O ( r · M n ω ) for undirected graphs. Then for every 1 ≤ i ≤d log / ( M n/r ) e , suppose we have an r (3 / i − -truncated DSO D i − , we can construct D i =Fast(Extend( D i − )) which is an r (3 / i -truncated DSO. This step costs ˜ O ( n M/ ( r (3 / i ))time. The preprocessing algorithm terminates when i = i ? = d log / ( M n/r ) e = O (log n ),and we obtain an r (3 / i ? -truncated DSO which is a (normal) DSO. Case 1: the input graph is undirected. The total preprocessing time is˜ O (cid:0) r · M n ω + n M/r (cid:1) = ˜ O (cid:16) n max { ω + a, − a } M (cid:17) . When a = (3 − ω ) / 2, this time complexity is ˜ O ( n (3+ ω ) / M ) = ˜ O ( n . M ).Therefore, given an undirected graph G = ( V, E ), there is a DSO with ˜ O ( n . M )preprocessing time and O (1) query time. Improved DSOs with Subcubic Preprocessing Time Case 2: the input graph is directed. The total preprocessing time is˜ O (cid:0) r M · MM ( n, n/r, n ) + n M/r (cid:1) = ˜ O (cid:16) n a + ω (1 − a ) M + n − a M (cid:17) . (Recall that ω (1 − a ) is the exponent of multiplying an n × n − a matrix and an n − a × n matrix.)Let a = 0 . − a = 0 . ω ( · ) [15], we have ω (1 − a ) ≤ ( a − . ω (0 . 7) + (0 . − a ) ω (0 . . − . . We substitute ω (0 . ≤ . ω (0 . ≤ . ω (1 − a ) ≤ · (( a − . · . . − a ) · . ≤ . . Therefore, given a directed graph G = ( V, E ), there is a DSO with˜ O (cid:16) n max { a + ω (1 − a ) , − a } M (cid:17) = ˜ O ( n . M ) . preprocessing time and O (1) query time. In this section, we prove Observation 2.1. Note that Observation 1.1 follows from Observa-tion 2.1 by setting r = + ∞ . (cid:73) Observation 2.1. Let r be an integer, G = ( V, E ) be an input graph, and D be an arbitrary r -truncated DSO. We can construct Fast( D ) , which is an r -truncated DSO with O (1) querytime and a preprocessing algorithm as follows.It first computes the distance matrix of G , and the (incoming and outgoing) shortest pathtrees rooted at each vertex.Then it invokes the preprocessing algorithm of D on the input graph G .At last, it makes ˜ O ( n ) queries to D , and spends ˜ O ( n ) additional time to finish thepreprocessing algorithm. We review and slightly modify the preprocessing algorithm of [3]. For convenience, we denote k p k r = min {k p k , r } for any path p and number r . Assigning priorities. We assign each vertex a priority , which is independently sampled fromthe following distribution: for any positive integer c , each vertex has priority c w.p. 1 / c .Denote c ( v ) the priority of the vertex v . With high probability, all of the following are true:The maximum priority is O (log n ).For every c ≤ O (log n ), there are ˜ O ( n/ c ) vertices with priority c .Let C be a large enough constant. For every shortest path uv with at least C · c log n edges, there is a vertex on uv whose priority is greater than c .In the following discussions, we will assume that all of the above assumptions hold.Fix a pair u, v ∈ V , let s i be the first vertex in uv with priority ≥ i , and t i be the lastsuch vertex. Then we can write the path uv as u (cid:32) s (cid:32) s (cid:32) . . . (cid:32) s O (log n ) (cid:32) t O (log n ) (cid:32) . . . (cid:32) t (cid:32) v. . Ren 9 We say that the vertices u, v, s i , t i are key vertices , and the i -th key vertex is denoted as k i .Then the path uv can also be written as u = k (cid:32) k (cid:32) . . . (cid:32) k O (log n ) = v. It is important to see that | k i k i +1 | ≤ C · min { c ( k i ) ,c ( k i +1 ) } log n (1)for every valid i , as otherwise there will be another key vertex between k i and k i +1 . Data structures for quick location. Suppose we are given a query ( u, v, f ), the first thingwe should do is to “locate” f , i.e. find the key vertices k i , k i +1 ∈ uv such that f ∈ k i k i +1 .We will utilize the following data (see also [2]). CL [ u, v, c ] (for “center left”): the first vertex in uv with priority at least c ; CR [ u, v, c ] (for “center right”): the last vertex in uv with priority at least c ; and BCP [ u, v ] (for “biggest center priority”): the maximum priority of any vertex on uv .It is easy to compute these data in ˜ O ( n ) time: for every u ∈ V , we perform a depth-firstsearch on the outgoing shortest path tree T out ( u ) to compute BCP [ u, · ]; for every u ∈ V andeach priority c , we also perform a depth-first search on T out ( u ) to compute CL [ u, · , c ] and CR [ u, · , c ].In addition, for every u, v ∈ V , we store the key vertices on uv into a hash table of size O (log n ). Given a (vertex) failure f , we can output whether f is among these key verticeson uv in O (1) worst-case time [10]. Data structures for avoiding a failure. We use D to preprocess the input graph. Then wecompute the following data: (Data a) For every u, v ∈ V , and every 1 ≤ i ≤ min { C · c ( u ) log n, | uv |} , let x i be the i -thvertex in the path uv . (Here u is the 0-th vertex.) We compute and store the value k uv (cid:5) x i k r . Also, let e i be the edge from x i − to x i , we compute and store k uv (cid:5) e i k r .Symmetrically, let x − i be the last i -th vertex in the path vu (not uv !), and e − i be the edge from x − i to x − ( i − . For every 1 ≤ i ≤ min { C · c ( u ) log n, | vu |} , wecompute and store k vu (cid:5) x − i k r and k vu (cid:5) e − i k r . (Data b) For every u, v ∈ V and consecutive key vertices k i , k i +1 ∈ uv , let y be the vertex inthe portion k i (cid:32) k i +1 that maximizes k uv (cid:5) y k r . We compute and store k uv (cid:5) y k r . (Data c) For every u, v ∈ V and key vertex k i ∈ uv , we compute and store k uv (cid:5) k i k r .For each priority c ≤ ˜ O (1), there are ˜ O ( n/ c ) vertices u whose priority is exactly c . In(Data a), we make ˜ O ( n c ) queries for each such u ( ˜ O (2 c ) queries for each v ∈ V ). Thereforein total, we make ˜ O ( n ) queries in (Data a). We will show in Section 3.3 that we can compute(Data b) using ˜ O ( n ) queries to D and ˜ O ( n ) additional time. (Data c) can be computed in˜ O ( n ) queries easily. Let ( u, v, f ) be a query. We first check whether f ∈ uv in the shortest path trees; if f uv ,then it is easy to see that k uv (cid:5) f k r = k uv k r .If f is a vertex failure, we check whether f is a key vertex on uv (that is, f = k i forsome i ), using the hash tables. If this is the case, we return k uv (cid:5) f k r stored in (Data c)immediately. Otherwise, we start by finding two consecutive key vertices k i , k i +1 ∈ uv such that f ∈ k i k i +1 . Recall that, if ‘ is the biggest priority of any vertex on uv , then the key verticeson uv are( u =) CL [ u, v, (cid:32) CL [ u, v, (cid:32) . . . (cid:32) CL [ u, v, ‘ ] (cid:32) CR [ u, v, ‘ ] (cid:32) . . . (cid:32) CR [ u, v, (cid:32) CR [ u, v, v ) . Denote a and b as the “tail” and “head” of f respectively. In particular, if f is a vertexfailure then a = b = f ; if f is an edge failure then it is an edge that goes from a to b . Wecan find k i in O (1) time using the following procedure:If BCP [ b, v ] = ‘ , then f is in the range ( u, CR [ u, v, ‘ ]), so k i = CL [ u, v, BCP [ u, a ]].Otherwise, f is in the range ( CR [ u, v, ‘ ] , v ) and we can see that k i = CR [ u, v, BCP [ b, v ] + 1].We can find k i +1 similarly. By Eq. (1), if k i = u , then | ub | ≤ C · c ( u ) log n , and we canlook up the value k uv (cid:5) f k r from (Data a) directly. Similarly, if k i +1 = v then we can alsolook up k uv (cid:5) f k r from (Data a).Now we assume that k i = u and k i +1 = v . A crucial observation is that k uv (cid:5) f k = min {k uk i +1 (cid:5) f k + k k i +1 v k , k uk i k + k k i v (cid:5) f k , k uv (cid:5) y k} , (2)where y is the vertex in [ k i , k i +1 ] that maximizes k uv (cid:5) y k . The proof of Eq. (2) is as follows: (i) If uv (cid:5) f goes through k i , then k uv (cid:5) f k = k uk i k + k k i v (cid:5) f k . (ii) If uv (cid:5) f goes through k i +1 , then k uv (cid:5) f k = k uk i +1 (cid:5) f k + k k i +1 v k . (iii) If uv (cid:5) f goes through neither k i nor k i +1 , then it avoids the entire portion of k i (cid:32) k i +1 ,thus also avoids y . We have k uv (cid:5) f k ≥ k uv (cid:5) y k . But k uv (cid:5) y k ≥ k uv (cid:5) a k by definition of y , and k uv (cid:5) a k ≥ k uv (cid:5) f k . (Recall that a is the “tail” of f .) Thus k uv (cid:5) f k = k uv (cid:5) y k .It is easy to see that a similar equation holds for r -truncated DSOs: k uv (cid:5) f k r = min {k uk i +1 (cid:5) f k r + k k i +1 v k , k uk i k + k k i v (cid:5) f k r , k uv (cid:5) y k r , r } , (3)where y is any vertex in [ k i , k i +1 ] that maximizes k uv (cid:5) y k r .Recall that we already know the values k uk i k and k k i +1 v k . To compute k uk i +1 (cid:5) f k r , wenote that if f is the last j -th vertex or edge in uk i +1 , then j ≤ C · c ( k i +1 ) log n . Thereforewe can look up the value of k uk i +1 (cid:5) f k r from (Data a). Similarly we can look up k k i v (cid:5) f k r .Finally, we can look up k uv (cid:5) y k r from (Data b).We can see that the query time is O (1). We will use the following notation. Let p be a path from u to v which is fixed in context,and a, b be two vertices in p . We will say that a < b if | p [ u, a ] | < | p [ u, b ] | , i.e. a appearsstrictly before b on the path p . Similarly, a > b , a ≤ b , a ≥ b mean | p [ u, a ] | > | p [ u, b ] | , | p [ u, a ] | ≤ | p [ u, b ] | , | p [ u, a ] | ≥ | p [ u, b ] | respectively.Let u, v ∈ V and s < t be two vertices on the path uv . Let y ∈ [ s, t ] be the vertex in [ s, t ]which maximizes k uv (cid:5) y k r . We first show that assuming we have built some oracles , we canfind this vertex y in O (log n ) oracle calls and O (log n ) additional time. The idea is to use abinary search described in [3, Section 6]. (cid:73) Lemma 3.1. Let r be an integer, u, v ∈ V , and s, t be two vertices on the path uv suchthat u < s < t < v . Suppose we have the following oracles, each with O (1) query time:an oracle that given a vertex x ∈ st , outputs k ut (cid:5) x k r ;an oracle that given a vertex x ∈ st , outputs k sv (cid:5) x k r ; . Ren 11 an oracle that given an interval [ s , t ] such that s ≤ s ≤ t ≤ t , outputs a vertex x ∈ [ s , t ] that maximizes the value k ut (cid:5) x k r .Then we can find a vertex y ∈ [ s, t ] which maximizes k uv (cid:5) y k r in O (log n ) time. u vs ts ′ t ′ qy Figure 2 If sv (cid:5) y does not go through t , then sv (cid:5) y does not go through the whole interval [ q, t ]. Proof. For any y ∈ [ s, t ], we denote h ( y ) = min {k ut (cid:5) y k r + k tv k , k us k + k sv (cid:5) y k r , r } . By Eq. (3), we have k uv (cid:5) y k r = min { h ( y ) , k uv (cid:5) y ? k r } where y ? is some vertex independentof y . Thus it suffices to find some y ∈ [ s, t ] that maximizes h ( y ).We use a binary search. Assume that we know the optimal y is in some interval [ s , t ],where s ≤ s < t ≤ t . (Initially we set s = s and t = t .) If | s t | = O (1) then we can usebrute force to find a vertex y ∈ [ s , t ] that maximizes h ( y ). Otherwise let q be the middlepoint of [ s , t ], and we use the third oracle to find a vertex y ∈ [ s , q ] that maximizes k ut (cid:5) y k r .There are two cases:If min {k ut (cid:5) y k r + k tv k , r } = h ( y ), then we can restrict our attention to the interval [ q, t ].This is because for every vertex x ∈ [ s , q ], h ( x ) ≤ min {k ut (cid:5) x k r + k tv k , r } ≤ min {k ut (cid:5) y k r + k tv k , r } = h ( y ) . Otherwise, h ( y ) = k us k + k sv (cid:5) y k r , and sv (cid:5) y does not go through t . Therefore sv (cid:5) y avoids every vertex in [ q, t ]. (See Figure 2.) For every vertex x ∈ [ q, t ], h ( x ) ≤ k us k + k sv (cid:5) x k r ≤ k us k + k sv (cid:5) y k r = h ( y ) . It follows that we can restrict our attention to the interval [ s , q ] now.Therefore, we can always shrink the length of our candidate interval [ s , t ] by a half. Itfollows that we can find the desired vertex y in O (log n ) time. (cid:74) Now we show how to compute (Data b) in ˜ O ( n ) time (assuming that (Data a) is ready).The most crucial ingredient is the following Range Maximum Query (RMQ) structures (usedin the third item of Lemma 3.1).For every u, v ∈ V , consider the following sequence (of length ‘ = min {| uv | − , C · c ( v ) log n } ):( k uv (cid:5) x − k r , k uv (cid:5) x − k r , . . . , k uv (cid:5) x − ‘ k r ) , where x − i denotes the last i -th vertex in the path uv ( v is the last 0-th). We build anRMQ structure of this sequence, which given a query ( s, t ) (1 ≤ s ≤ t ≤ ‘ ), outputs anumber i ∈ [ s, t ] that maximizes k uv (cid:5) x − i k r . After we compute the above sequence, thisdata structure can be preprocessed in O ( ‘ ) time, and each query costs O (1) time [1].For every priority c ≤ O (log n ), there are ˜ O ( n/ c ) vertices v of this priority, and for eachvertex v we construct n RMQ structures (one for each u ∈ V ) on length- ˜ O (2 c ) sequences.The total size of these RMQ structures is O (log n ) X c =1 ˜ O ( n/ c ) · n · ˜ O (2 c ) = ˜ O ( n ) . Therefore, these RMQ structures can be preprocessed in ˜ O ( n ) time. (Note that everyelement k uv (cid:5) x − i k r is already computed in (Data a).)To compute (Data b), we enumerate u, v, k i , k i +1 where k i , k i +1 are consecutive keyvertices in uv . There are ˜ O ( n ) possible combinations of ( u, v, k i , k i +1 ). As argued inSection 3.2, we know that the following data are already computed in (Data a): k uk i +1 (cid:5) x k r , for any x ∈ k i k i +1 ; k k i v (cid:5) x k r , for any x ∈ k i k i +1 .We also have the following RMQ oracles constructed above:An oracle that given any interval [ s , t ] on the path uv such that k i ≤ s ≤ t ≤ k i +1 ,finds the vertex y ∈ [ s , t ] that maximizes k uk i +1 (cid:5) y k r in O (1) time.It follows from Lemma 3.1 that we can find a vertex y ∈ [ k i , k i +1 ] that maximizes k uv (cid:5) y k r in O (log n ) time. The total time for computing (Data b) is thus ˜ O ( n ). The main open problem after this work is to improve the preprocessing time for DSOs. Canwe improve the preprocessing time for directed graphs to ˜ O ( n . M ), matching the currentbest algorithm for APSP in directed graphs [22]? Or at least can we achieve a preprocessingtime of ˜ O ( n . M ), under the assumption that ω = 2?Also, can we extend our technique to deal with negative weights? There are a fewcandidate definitions of “ r -truncated DSOs” in this case, if we interpret r as the number ofedges in the shortest path, instead of the length of the shortest path. For example, we maydefine a DSO is r -truncated if on a query ( u, v, f ), it outputs some value no less than k uv (cid:5) f k ,and when | uv (cid:5) f | ≤ r , it outputs k uv (cid:5) f k exactly. However, it seems that every definitionof “ r -truncated DSO” that we tried were not compatible with arguments in Section 3.3.It is annoying that the shortest paths are usually not unique in a graph with small integeredge weights. For directed graphs, Theorem 1.4 shows that we can compute a set of incomingand outgoing shortest path trees that satisfies Theorem 1.3 in ˜ O ( n (3+ ω ) / M / ) time. Canwe achieve the same requirements in ˜ O ( n . M ) time, matching the current best algorithmfor APSP? References Michael A. Bender and Martin Farach-Colton. The LCA problem revisited. In Gaston H.Gonnet, Daniel Panario, and Alfredo Viola, editors, LATIN 2000: Theoretical Informatics,4th Latin American Symposium, Punta del Este, Uruguay, April 10-14, 2000, Proceedings ,volume 1776 of Lecture Notes in Computer Science , pages 88–94. Springer, 2000. URL: https://doi.org/10.1007/10719839_9 . Aaron Bernstein and David R. Karger. Improved distance sensitivity oracles via randomsampling. In Shang-Hua Teng, editor, Proceedings of the Nineteenth Annual ACM-SIAMSymposium on Discrete Algorithms, SODA 2008, San Francisco, California, USA, January20-22, 2008 , pages 34–43. SIAM, 2008. URL: http://dl.acm.org/citation.cfm?id=1347082.1347087 . Aaron Bernstein and David R. Karger. A nearly optimal oracle for avoiding failed verticesand edges. In Michael Mitzenmacher, editor, Proceedings of the 41st Annual ACM Symposiumon Theory of Computing, STOC 2009, Bethesda, MD, USA, May 31 - June 2, 2009 , pages101–110. ACM, 2009. URL: https://doi.org/10.1145/1536414.1536431 . Shiri Chechik and Sarel Cohen. Distance sensitivity oracles with subcubic preprocessingtime and fast query time. In Konstantin Makarychev, Yury Makarychev, Madhur Tulsiani, . Ren 13 Gautam Kamath, and Julia Chuzhoy, editors, Proccedings of the 52nd Annual ACM SIGACTSymposium on Theory of Computing, STOC 2020, Chicago, IL, USA, June 22-26, 2020 , pages1375–1388. ACM, 2020. URL: https://doi.org/10.1145/3357713.3384253 . Camil Demetrescu and Giuseppe F. Italiano. A new approach to dynamic all pairs shortestpaths. J. ACM , 51(6):968–992, 2004. URL: https://doi.org/10.1145/1039488.1039492 . Camil Demetrescu, Mikkel Thorup, Rezaul Alam Chowdhury, and Vijaya Ramachandran.Oracles for distances avoiding a failed node or link. SIAM J. Comput. , 37(5):1299–1318, 2008.URL: https://doi.org/10.1137/S0097539705429847 . Ran Duan and Seth Pettie. Dual-failure distance and connectivity oracles. In Claire Mathieu,editor, Proceedings of the Twentieth Annual ACM-SIAM Symposium on Discrete Algorithms,SODA 2009, New York, NY, USA, January 4-6, 2009 , pages 506–515. SIAM, 2009. URL: http://dl.acm.org/citation.cfm?id=1496770.1496826 . Ran Duan and Seth Pettie. Fast algorithms for (max, min)-matrix multiplication and bottleneckshortest paths. In Claire Mathieu, editor, Proceedings of the Twentieth Annual ACM-SIAMSymposium on Discrete Algorithms, SODA 2009, New York, NY, USA, January 4-6, 2009 ,pages 384–391. SIAM, 2009. URL: http://dl.acm.org/citation.cfm?id=1496770.1496813 . Ran Duan and Tianyi Zhang. Improved distance sensitivity oracles via tree partitioning.In Faith Ellen, Antonina Kolokolova, and Jörg-Rüdiger Sack, editors, Algorithms and DataStructures - 15th International Symposium, WADS 2017, St. John’s, NL, Canada, July 31- August 2, 2017, Proceedings , volume 10389 of Lecture Notes in Computer Science , pages349–360. Springer, 2017. URL: https://doi.org/10.1007/978-3-319-62127-2_30 . Michael L. Fredman, János Komlós, and Endre Szemerédi. Storing a sparse table with O (1)worst case access time. In , pages 165–169. IEEE Computer Society, 1982.URL: https://doi.org/10.1109/SFCS.1982.39 . François Le Gall. Powers of tensors and fast matrix multiplication. In Katsusuke Nabeshima,Kosaku Nagasaka, Franz Winkler, and Ágnes Szántó, editors, International Symposium onSymbolic and Algebraic Computation, ISSAC ’14, Kobe, Japan, July 23-25, 2014 , pages296–303. ACM, 2014. URL: https://doi.org/10.1145/2608628.2608664 . Francois Le Gall and Florent Urrutia. Improved rectangular matrix multiplication usingpowers of the Coppersmith-Winograd tensor. In Artur Czumaj, editor, Proceedings of theTwenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2018, NewOrleans, LA, USA, January 7-10, 2018 , pages 1029–1046. SIAM, 2018. URL: https://doi.org/10.1137/1.9781611975031.67 . Fabrizio Grandoni and Virginia Vassilevska Williams. Faster replacement paths and distancesensitivity oracles. ACM Trans. Algorithms , 16(1):15:1–15:25, 2020. URL: https://doi.org/10.1145/3365835 , doi:10.1145/3365835 . Andrea Lincoln, Virginia Vassilevska Williams, and R. Ryan Williams. Tight hardnessfor shortest cycles and paths in sparse graphs. In Artur Czumaj, editor, Proceedings ofthe Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2018,New Orleans, LA, USA, January 7-10, 2018 , pages 1236–1252. SIAM, 2018. URL: https://doi.org/10.1137/1.9781611975031.80 . Grazia Lotti and Francesco Romani. On the asymptotic complexity of rectangular matrixmultiplication. Theor. Comput. Sci. , 23:171–185, 1983. URL: https://doi.org/10.1016/0304-3975(83)90054-3 . Ketan Mulmuley, Umesh V. Vazirani, and Vijay V. Vazirani. Matching is as easy as matrixinversion. Combinatorica , 7(1):105–113, 1987. URL: https://doi.org/10.1007/BF02579206 . Hanlin Ren. Improved distance sensitivity oracles with subcubic preprocessing time. 2020. Toappear in ESA’20. Raimund Seidel. On the all-pairs-shortest-path problem in unweighted undirected graphs. J.Comput. Syst. Sci. , 51(3):400–403, 1995. URL: https://doi.org/10.1006/jcss.1995.1078 . Avi Shoshan and Uri Zwick. All pairs shortest paths in undirected graphs with integerweights. In , pages 605–615. IEEE Computer Society, 1999. URL: https://doi.org/10.1109/SFFCS.1999.814635 . Noam Ta-Shma. A simple proof of the isolation lemma. Electronic Colloquium on Computa-tional Complexity (ECCC) , 22:80, 2015. URL: https://eccc.weizmann.ac.il/report/2015/080 . Oren Weimann and Raphael Yuster. Replacement paths and distance sensitivity oracles viafast matrix multiplication. ACM Trans. Algorithms , 9(2):14:1–14:13, 2013. URL: https://doi.org/10.1145/2438645.2438646 . Uri Zwick. All pairs shortest paths using bridging sets and rectangular matrix multiplication. J. ACM , 49(3):289–317, 2002. URL: https://doi.org/10.1145/567112.567114 . A Breaking Ties for Non-unique Shortest Paths In this section, we prove Theorem 1.3 and 1.4.Recall that in a subgraph G of G , we denote w G ( u, v ) as the largest (w.r.t. ≺ ) edge w such that there is a shortest path from u to v whose bottleneck edge (i.e. smallest w.r.t. ≺ ) is w . Also the path ρ G ( u, v ) is defined, inductively from the smallest k uv k to the largest k uv k ,as follows: If u = v , then ρ G ( u, v ) is the empty path; otherwise, suppose w G ( u, v ) is an edgefrom u ? to v ? , then ρ G ( u, v ) is the concatenation of ρ G ( u, u ? ), w G ( u, v ) and ρ G ( v ? , v ). (cid:73) Theorem 1.3. The following properties of ρ G ( u, v ) are true: (Property a) For every u , v ∈ ρ G ( u, v ) such that u appears before v , the portion of u (cid:32) v in ρ G ( u, v ) coincides with the path ρ G ( u , v ) . (Property b) Let G be a subgraph of G , suppose ρ G ( u, v ) is completely contained in G , then ρ G ( u, v ) = ρ G ( u, v ) . Proof. In this proof we will always use the following notation: Let w = w G ( u, v ), andsuppose w is an edge from u ? to v ? . Denote p = ρ G ( u, u ? ) and p = ρ G ( v ? , v ). We willprove Theorem 1.3 inductively, from the smallest k uv k to the largest k uv k . Theorem 1.3 isclearly true when u = v . u vwu ⋆ v ⋆ u ′ v ′ | {z } p | {z } p (Property a): If both u , v ∈ p , then (Property a) is true by induction on p . Similarly,if both u , v ∈ p , then (Property a) is also true by induction on p .Now suppose u ∈ p and v ∈ p . Our first observation is that w G ( u , v ) = w G ( u, v ) = w .Actually, since ( ρ G ( u, v ))[ u , v ] is a shortest path from u to v with bottleneck edge w , wehave w G ( u , v ) (cid:23) w . But if there is any shortest path p from u to v whose bottleneckedge is (cid:31) w , the concatenation of p [ u, u ], p and p [ v , v ] will be a shortest path from u to v with bottleneck edge (cid:31) w , a contradiction. Thus we can only have w G ( u , v ) = w .By induction on p , we have ρ G ( u , u ? ) = p [ u , u ? ]. By induction on p , we have ρ G ( v ? , v ) = p [ v ? , v ]. Therefore, ρ G ( u , v ) is the concatenation of p [ u , u ? ], w , and p [ v ? , v ].This path coincides with the u (cid:32) v portion of ρ G ( u, v ).(Property b): it suffices to prove w G ( u, v ) = w G ( u, v ), and use induction on p and p .Since G is a subgraph of G , and the distance from u to v is the same in G and G , we have . Ren 15 w G ( u, v ) (cid:23) w G ( u, v ). Since ρ G ( u, v ) is completely in G and the bottleneck edge of ρ G ( u, v )is w G ( u, v ), we have w G ( u, v ) (cid:23) w G ( u, v ). This completes the proof. (cid:74)(cid:73) Theorem 1.4 ([8]) . Given a subgraph G , the incoming and outgoing shortest path trees T in ( u ) and T out ( u ) for each vertex u can be computed in ˜ O ( n (3+ ω ) / M / ) time. Proof Sketch. The first step is to compute w G ( u, v ) for every pair of vertices u, v ∈ V .This problem is exactly the same as the all-pairs bottleneck shortest paths problem (APBSP;[8, Theorem 4.4]). However, Theorem 4.4 of [8] only claims to work for unweighted graphs,so we verify that it also works for graphs with positive integer weights here.We start by using [22] to compute k ρ G ( u, v ) k for every u, v ∈ V . Then, for every0 ≤ i ≤ d log / ( nM ) e and r = (3 / i , assuming we have computed w G ( u, v ) for every u, v such that k ρ G ( u, v ) k ≤ r , we compute w G ( u, v ) for every u, v such that k ρ G ( u, v ) k ≤ (3 / r . This is done as follows. We sample a vertex set H by adding each vertex into H independently w.p. Θ( M log n/r ), then w.h.p. H hits mid ( ρ G ( u, v )) for every u, v such that r < k ρ G ( u, v ) k ≤ (3 / r . (Recall that mid ( ρ G ( u, v )) is the “middle 1 / ρ G ( u, v ).)Let D, W be V × H matrices such that for every u ∈ V, h ∈ H , D [ u, h ] = ( k ρ G ( u, h ) k k ρ G ( u, h ) k ≤ r + ∞ k ρ G ( u, h ) k > r ; W [ u, h ] = ( w G ( u, h ) k ρ G ( u, h ) k ≤ r −∞ k ρ G ( u, h ) k > r . Then we compute the Distance-Max-Min product (Definition 4.3 of [8]) of ( D, W ) and( D T , W T ) to obtain a V × V matrix W such that W [ u, v ] = max h : D [ u,h ]+ D [ h,v ]= k ρ G ( u,v ) k { min { W [ u, h ] , W [ h, v ] }} . We can see that W [ u, v ] = w G ( u, v ) for every u, v ∈ V such that r < k ρ G ( u, v ) k ≤ (3 / r .This completes the description of the APBSP algorithm.Now we analyze the time complexity. Let | H | = n s , then r = ˜ O ( n − s M ), and the finiteentries in D are in { , , . . . , r } . by [8, Theorem 4.3], the Distance-Max-Min product takes O (cid:16) min n n s , r / n s/ ω ( s ) / o(cid:17) = ˜ O (cid:16) min n n s , n (3+ ω ( s )) / M / o(cid:17) ≤ ˜ O (cid:16) n (3+ ω ) / M / (cid:17) time. Since we only execute O (log n ) rounds of Distance-Max-Min product, the overallrunning time of the algorithm is ˜ O (cid:0) n (3+ ω ) / M / (cid:1) .Now we construct the outgoing shortest path trees from the table of w G ( u, v ) for every u, v ∈ V . It suffices to compute the parents of each node v in the trees T out ( u ) (which wedenote as parent u ( v )). We compute parent u ( v ) inductively from the smallest k uv k to thelargest.Let ( u, v ) be the pair of vertices we are processing, and assume that for every u , v ∈ V such that k u v k < k uv k , we have already computed parent u ( v ). Suppose w G ( u, v ) isan edge from u ? to v ? . If v ? = v , then parent u ( v ) = u ? . Otherwise, it is easy to seethat k ρ G ( v ? , v ) k < k ρ G ( u, v ) k and parent u ( v ) = parent v ? ( v ). Thus we can compute everyoutgoing shortest path tree in ˜ O ( n ) time. Similarly, the incoming shortest path trees canalso be computed in ˜ O ( n ) time.) time.