This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

A Bottom-Up Algorithm for Negative-Weight
SSSP with Integrated Negative Cycle Finding

Jason Li Carnegie Mellon University, [email protected]    Connor Mowry Carnegie Mellon University, [email protected]
Abstract

We present a simplified algorithm for solving the Negative-Weight Single-Source Shortest Paths (SSSP) problem, focusing on enhancing clarity and practicality over prior methods. Our algorithm uses graph diameter as a recursive parameter, offering greater robustness to the properties of the decomposed graph compared to earlier approaches. Additionally, we fully integrate negative-weight cycle finding into the algorithm by augmenting the Bellman-Ford/Dijkstra hybrid, eliminating the need for a separate cycle-finding procedure found in prior methods. Although the algorithm achieves no theoretical efficiency gains, it simplifies negative cycle finding and emphasizes design simplicity, making it more accessible for implementation and analysis. This work highlights the importance of robust parameterization and algorithmic simplicity in addressing the challenges of Negative-Weight SSSP.

1 Introduction

The Single-Source Shortest Paths (SSSP) problem with negative edge weights is a cornerstone of algorithmic graph theory, with applications spanning network optimization, logistics, and resource allocation. An important extension of this problem involves handling graphs that may contain negative-weight cycles, where the goal is to either return a shortest path tree or find a negative-weight cycle. Both outputs serve as verifiable certificates, ensuring correctness and reliability.

Scaling has been a foundational technique in shortest path algorithms since the 1990s [Gol95]. Initially, it was used to normalize edge weights, reducing the problem to one where all negative edges have weight exactly 1-1. More recently, scaling has been applied to transform cycle properties, ensuring that non-negative-weight cycles become significantly more positive. This transformation enables efficient computation of SSSP on the scaled graph. Algorithms such as those in the Bernstein-Nanongkai-Wulff-Nilsen [BNW22] framework have integrated scaling with advanced decomposition techniques, achieving near-linear time complexity for solving the Negative-Weight SSSP problem.

Building on this foundation, Bringmann, Cassis, and Fischer [BCF23] extended the existing framework, achieving a nearly 6-log-factor improvement over [BNW22]. Their work set a new standard for solving Negative-Weight SSSP, providing both theoretical advancements and practical insights.

In this paper, we build upon the techniques introduced by [BCF23], presenting a bottom-up algorithm inspired by [FHL+25] with the following contributions:

  1. 1.

    Diameter-Based Decomposition Parameter: Our algorithm employs the diameter of the non-negative graph as a parameter in our recursive decomposition, similar to the bottom-up approach of [FHL+25]. Compared to [BNW22] and [BCF23]’s parameterization of the maximum number of negative-weight edges on any shortest path, this parameterization is more natural and, more importantly, avoids the issue of undetected failures in the presence of negative-weight cycles. In particular, we bypass the noisy binary search analysis of [BCF23], which they must perform to handle the case of undetected failures.

  2. 2.

    Integrated Negative Cycle Finding: The diameter-based decomposition allows us to augment the Bellman-Ford/Dijkstra hybrid algorithm to look for negative-weight cycles on the fly. In other words, we fully integrate negative-weight cycle finding into our algorithm, instead of designing a separate procedure as in [BCF23].

Although our algorithm does not improve upon the theoretical efficiency of [BCF23], it emphasizes simplicity in design and implementation, making it an accessible and practical alternative for solving the Negative-Weight SSSP problem.

Theorem 1.

Consider a graph with integral edge weights that are at least W-W. There is a Las Vegas algorithm that solves Negative-Weight SSSP in O((m+nloglogn)log2nlog(nW))O((m+n\log\log n)\log^{2}n\log(nW)) time with high probability.

1.1 Preliminaries

Let G=(V,E,wG)G=(V,E,w_{G}) be a directed graph with integral weight function wG:Ew_{G}:E\to\mathbb{Z}. A potential function ϕ:V\phi:V\to\mathbb{R} is a function on the vertices used to reweight the graph: the reweighted graph GϕG_{\phi} satisfies wGϕ(uv)=wG(uv)+ϕ(u)ϕ(v)w_{G_{\phi}}(uv)=w_{G}(uv)+\phi(u)-\phi(v) for all edges uvEuv\in E. A result of Johnson [Joh77] reduces the Negative-Weight SSSP problem to computing a potential function ϕ\phi such that all edge weights of GϕG_{\phi} are non-negative, after which Dijkstra’s algorithm can be run on GϕG_{\phi} to recover the single-source shortest paths in GG.

The iterative scaling technique of [BNW22] does not compute such a potential function in one go. Instead, if the graph GG has all edge weights at least W-W, then the goal is to either compute a potential function ϕ\phi such that GϕG_{\phi} has all edge weights at least W/2-W/2, or output a negative-weight cycle; we call this problem Scale[BNW22] show that Negative-Weight SSSP reduces to O(log(nW))O(\log(nW)) iterations of Scale when the original graph has all edge weights at least W-W. Moreover, [BCF23] show that if each iteration of Scale runs in TT time in expectation, then Negative-Weight SSSP can be computed in O(Tlog(nW))O(T\log(nW)) time with high probability111With high probability means with probability at least 11/nC1-1/n^{C} for arbitrarily large constant C>0C>0. (and with Las Vegas guarantee) by restarting any runs of Scale that exceed 2T2T time and applying a Chernoff bound. Hence, to obtain Theorem 1, we only focus on the task of solving Scale in O((m+nloglogn)log2n)O((m+n\log\log n)\log^{2}n) expected time. It even suffices to solve Scale in this time with high probability, since the solution can be easily checked for correctness and Scale can be restarted if incorrect.

We need three main subroutines from [BNW22, BCF23]. The first is the Decompose subroutine introduced in [BNW22] and refined in [BCF23]. Define the in-ball/out-ball of radius rr centered at vv as the set of vertices reachable to/from vv by a path of weight at most rr, respectively. Given a graph GG, define the graph G0G_{\geq 0} as the graph GG with all negative-weight edges reweighted to 0. We require the following guarantee from [BCF23]:

Lemma 2 (Lemma 8 of [BCF23]).

There is a randomized algorithm Decompose(G,d)(G,d) running in expected time O((m+nloglogn)logn)O((m+n\log\log n)\log n) that computes a set SES\subseteq E of positive-weight edges such that:

  1. 1.

    Progress: With high probability, for any strongly connected component CC in GSG\setminus S, either (i) |C|34|V||C|\leq\frac{3}{4}|V| or (ii) for each vertex vCv\in C, both the in-ball and out-ball of radius d4\frac{d}{4} centered at vv contain more than |V|2\frac{|V|}{2} vertices.

  2. 2.

    Sparse Hitting: For any (potentially non-simple) path PP of length at most dd in G0G_{\geq 0}, the number of edges of PP inside SS (counting multiplicity) has expectation at most O(logn)O(\log n).

We remark that Lemma 8 of [BCF23] proves a different condition (ii) for progress that depends on a parameter κ\kappa that they introduce. However, our new condition (ii) also holds and is mentioned in the proof of their Lemma 22.

The second subroutine is a Bellman-Ford/Dijkstra hybrid algorithm for Negative-Weight SSSP, also introduced in [BNW22] and refined in [BCF23]. For convenience, we do not mention a source vertex in the input to BellmanFordDijkstra. Instead, the goal is to compute, for each vertex vVv\in V, the shortest path ending at vv (and starting from anywhere). Note that the shortest path has weight at most 0 since the empty path at vv of weight 0 is a possible choice. To frame this problem as SSSP, simply add a source vertex ss with zero-weight edges to each vertex in VV, and call SSSP on the new graph GsG_{s} with source ss. For further convenience, we also integrate a potential function ϕ:V\phi:V\to\mathbb{R} directly into BellmanFordDijkstra, which runs the Bellman-Ford/Dijkstra hybrid on (Gs)ϕ(G_{s})_{\phi} instead (with the extension ϕ(s)=0\phi(s)=0), and quickly finds single-source shortest paths with few negative-weight edges in (Gs)ϕ(G_{s})_{\phi}. These single-source shortest paths in (Gs)ϕ(G_{s})_{\phi} correspond exactly to single-source shortest paths in GsG_{s}, which in turn correspond to shortest paths in GG ending at each vertex.

In the version below, we also include the algorithm’s guarantees after each iteration ii to allow for early termination if a negative-weight cycle is detected. In addition, we also maintain the weights of our current shortest paths under a separate, auxiliary weight function ww^{\prime}. This can be implemented by recording the distance of each current path PP as a tuple (wG(P),w(P))(w_{G}(P),w^{\prime}(P)), but only using the first coordinate for comparisons.

Lemma 3 (Lemmas 25 and 62 of [BCF23]).

Let G=(V,E,wG)G=(V,E,w_{G}) be a directed graph and ϕ\phi be a potential function. For each vertex vVv\in V, let ηG,ϕ(v)\eta_{G,\phi}(v) be the minimum number of edges of negative weight in GϕG_{\phi} among all shortest paths in GG ending at vv. There is an algorithm BellmanFordDijkstra(G,ϕ)(G,\phi) that computes a shortest path ending at each vertex in time O(v(deg(v)+loglogn)ηG,ϕ(v))O(\sum_{v}(\deg(v)+\log\log n)\cdot\eta_{G,\phi}(v)).

The first ii iterations of the algorithm runs in O((m+nloglogn)i)O((m+n\log\log n)\cdot i) time and computes, for each vertex vVv\in V, the minimum weight di(v)d_{i}(v) of a path Pi(v)P_{i}(v) from ss to vv among those that contains less than ii negative-weight edges. Moreover, given input auxiliary weights ww^{\prime} on the edges (independent of the weights wGw_{G} that determine shortest paths), the algorithm can also compute the weight di(v)d_{i}^{\prime}(v) under ww^{\prime} of some such path Pi(v)P_{i}(v).

The third subroutine is given a graph with its strongly connected components and a potential function, and fixes the DAG edges outside the SCCs while keeping the edge weights inside the SCCs non-negative.

Lemma 4 (Lemma 3.2 of [BNW22]).

Consider a graph GG with strongly connected components C1,,CC_{1},\ldots,C_{\ell} and a potential function ϕ\phi, and suppose that all edges inside the SCCs have non-negative weight in GϕG_{\phi}. There is an O(n+m)O(n+m) time algorithm that adjusts ϕ\phi so that all edge weights in GϕG_{\phi} are now non-negative.

2 The Scale Algorithm

Recall the specifications of the Scale problem: given an input graph G=(V,E,wG)G=(V,E,w_{G}) with edge weights wG(e)Ww_{G}(e)\geq-W for all eEe\in E, either return a reweighted graph GϕG_{\phi} with weights at least W/2-W/2 or output a negative-weight cycle in GG. We present an algorithm that runs in expected time O((m+loglogn)log2n)O\left((m+\log\log n)\log^{2}n\right) and succeeds with high probability, which is sufficient to prove Theorem 1.

2.1 Description

The algorithm operates in two main phases: (1) recursively decomposing a scaled version of the input graph, and (2) iteratively computing distances on the decomposition.

2.1.1 Phase 1: Recursive Decomposition

Let G=(V,E,wG)G=(V,E,w_{G}) be the input graph. We define a scaled graph G=(V,E,wG)G^{\prime}=(V,E,w_{G^{\prime}}) by increasing the weight of every edge by W/2W/2, i.e., wG(e)=wG(e)+W/2w_{G^{\prime}}(e)=w_{G}(e)+W/2 for all edges eEe\in E.

The decomposition process uses the Decompose algorithm from [BCF23], which, given a graph and a diameter parameter dd, returns a set of edges whose removal ensures that the remaining strongly connected components (SCCs) are either small in size (condition (i) of Lemma 2) or have diameter at most d/2d/2 (which we will deduce from condition (ii)). Starting with d0=nW/2d_{0}=nW/2, we decompose GG^{\prime} recursively. For each subgraph HH with parameter dd, we compute the set of cut edges S(H,d)=Decompose(H,d)S_{(H,d)}=\textsc{Decompose}(H,d) and remove these edges to obtain SCCs C1,C2,,CC_{1},C_{2},\dots,C_{\ell}. For each SCC CiC_{i}, the diameter parameter did_{i} is set to dd if |Ci|34|V(H)||C_{i}|\leq\frac{3}{4}|V(H)|, or d/2d/2 otherwise. If di>W/2d_{i}>W/2, we recursively decompose CiC_{i}; otherwise, CiC_{i} becomes a leaf node.

Once the decomposition is complete, we check each leaf node for the presence of a negative edge uvuv. If such an edge exists, then we claim there must be a negative-weight cycle in GG. To find a negative-weight cycle, we run Dijkstra’s algorithm from vv in G0G^{\prime}_{\geq 0} (where negative-weight edges in GG^{\prime} are replaced by edges of weight 0) to find a path to uu of weight at most W/2W/2 in G0G^{\prime}_{\geq 0}; we will show that such a path must exist. Note that this path also has weight at most W/2W/2 in GG, where edge weights are only smaller. The algorithm then outputs the cycle formed by concatenating this path with the edge uvuv, which is a negative-weight cycle since the edge uvuv has negative weight in GG^{\prime} and hence weight less than W/2-W/2 in GG.

At this point, if the algorithm does not terminate early with a negative-weight cycle, then all edges in leaf nodes are non-negative.

2.1.2 Phase 2: Iterative Distance Computation

In this phase, we iteratively compute distance estimates on the decomposition tree, starting from the leaves and moving up to the root. Initially, we set ϕ(v)=0\phi(v)=0 for all vVv\in V. For each node (H,d)(H,d) in the decomposition tree, we skip further computation if (H,d)(H,d) is a leaf, as all edges in HH are non-negative. For a non-leaf node (H,d)(H,d), assume that we have already computed a ϕ\phi such that all SCCs of (HS(H,d))ϕ(H\setminus S_{(H,d)})_{\phi} have non-negative weights. Using Lemma 4, we adjust ϕ\phi so that all edges of (HS(H,d))ϕ(H\setminus S_{(H,d)})_{\phi} now have non-negative weights. We then run BellmanFordDijkstra on HH with potential function ϕ\phi, and use wG0w_{G^{\prime}_{\geq 0}} as an auxiliary function to help detect a negative-weight cycle.

If BellmanFordDijkstra records a path with auxiliary weight more than dd, then we terminate BellmanFordDijkstra early and recover such a path PP with endpoints uu and vv. We then run Dijkstra’s algorithm from vv in G0G^{\prime}_{\geq 0} to find a shortest path PP^{\prime} back to uu. We show that concatenating PP and PP^{\prime} produces a negative-weight cycle in GG.

After processing all nodes at the current level, we update ϕ\phi and proceed to the next level. After processing all the levels, we guarantee that GϕG^{\prime}_{\phi} has non-negative weight edges everywhere.

2.2 Algorithm Pseudocode

Algorithm 1 Scale Algorithm
1:function Scale(G=(V,E,wG),WG=(V,E,w_{G}),W) \triangleright Input: Graph GG with wG(e)Ww_{G}(e)\geq-W
2:     for all edges eEe\in E do
3:         wG(e)wG(e)+W/2w_{G^{\prime}}(e)\leftarrow w_{G}(e)+W/2
4:     end for
5:     G(V,E,wG)G^{\prime}\leftarrow(V,E,w_{G^{\prime}})
6:     // Phase 1: Recursive Decomposition
7:     d0nW/2d_{0}\leftarrow nW/2
8:     BuildDecompositionTree(GG^{\prime}, d0d_{0})
9:     for all leaf nodes (H,d)(H,d) in the decomposition tree do
10:         if exists edge uvE(H)uv\in E(H) with wH(uv)<0w_{H}(uv)<0 then
11:              Run Dijkstra’s algorithm from vv in G0G^{\prime}_{\geq 0}
12:              Let PP be the path from vv to uu in G0G^{\prime}_{\geq 0}
13:              return negative-weight cycle formed by P+uvP+uv
14:         end if
15:     end for
16:     // Phase 2: Iterative Distance Computation
17:     ϕ\phi\leftarrow\ IterativeDistanceComputation(G,DecompositionTreeG^{\prime},\text{DecompositionTree})
18:     return the final potential function ϕ\phi
19:end function
Algorithm 2 Phase 1: BuildDecompositionTree
1:function BuildDecompositionTree(HH, dd)
2:     S(H,d)S_{(H,d)}\leftarrow Decompose(HH, dd)
3:     Remove edges S(H,d)S_{(H,d)} from HH to obtain SCCs C1,C2,,CC_{1},C_{2},\dots,C_{\ell}
4:     for all i[]i\in[\ell] do
5:         if |Ci|34|V(H)||C_{i}|\leq\frac{3}{4}|V(H)| then
6:              didd_{i}\leftarrow d
7:         else
8:              did/2d_{i}\leftarrow d/2
9:         end if
10:         if di>W/2d_{i}>W/2 then
11:              BuildDecompositionTree(CiC_{i}, did_{i})
12:         end if
13:     end for
14:end function
Algorithm 3 Phase 2: IterativeDistanceComputation
1:function IterativeDistanceComputation(G,DecompositionTreeG^{\prime},\text{DecompositionTree})
2:     Initialize ϕ(v)0\phi(v)\leftarrow 0 for all vVv\in V
3:     for all levels \ell from bottom to top in the decomposition tree do
4:         for all nodes (H,d)(H,d) at level \ell do
5:              if (H,d)(H,d) is a leaf then
6:                  Skip leaf nodes \triangleright All edges are non-negative
7:              else
8:                  Adjust ϕ\phi so DAG edges are non-negative \triangleright Lemma 4
9:                  Run BellmanFordDijkstra(H,ϕ)(H,\phi) with auxiliary weight wH0w_{H_{\geq 0}}, performing:
10:                  for all iterations ii during BellmanFordDijkstra do
11:                       Compute values di(v)d_{i}(v) and di(v)d^{\prime}_{i}(v) for all vVv\in V
12:                       if di(v)>dd^{\prime}_{i}(v)>d for some vertex vv then
13:                           Recover the path PP from uu to vv with auxiliary weight exceeding dd
14:                           Run Dijkstra’s algorithm from vv in G0G^{\prime}_{\geq 0}
15:                           Let PP^{\prime} be the path from vv to uu in G0G^{\prime}_{\geq 0}
16:                           return negative-weight cycle formed by P+PP+P^{\prime}
17:                       end if
18:                  end for
19:                  Update ϕnxt(v)\phi_{\text{nxt}}(v)\leftarrow computed distance for all vV(H)v\in V(H)
20:              end if
21:         end for
22:         ϕϕnxt\phi\leftarrow\phi_{\text{nxt}} \triangleright HϕH_{\phi} has non-negative weights for each (H,d)(H,d) on level \ell
23:     end for
24:     return the final potential function ϕ\phi
25:end function

2.3 Analysis

Our ultimate goal is to prove the following theorem.

Theorem 5.

There is an algorithm Scale such that, for any input graph G=(V,E,wG)G=(V,E,w_{G}) with edge weights wG(e)Ww_{G}(e)\geq-W for all eEe\in E, Scale(G)(G) either returns a reweighted graph GϕG_{\phi} with edge weights at least W/2-W/2, or outputs a negative-weight cycle in GG. The algorithm runs in expected time O((m+loglogn)log2n)O\left((m+\log\log n)\log^{2}n\right) and succeeds with high probability.

To prove this theorem, we establish several intermediate results. Below, we say that a vertex subset UVU\subseteq V has diameter at most dd in a graph G=(V,E)G=(V,E) if for any two vertices u,vUu,v\in U, there is a path in GG from uu to vv of weight at most dd. Throughout, we condition on the progress property of Lemma 2 succeeding for all decompositions, which occurs with high probability.

Claim 6.

Let (H,d)(H,d) be a non-leaf node in the decomposition tree, and let CC be a strongly connected component (SCC) of HS(H,d)H\setminus S_{(H,d)} such that |C|>34|V(H)||C|>\frac{3}{4}|V(H)|. Then, with high probability, CC has diameter at most d2\frac{d}{2} in H0H_{\geq 0} (and in G0G^{\prime}_{\geq 0}).

Proof.

Consider a SCC CC of HS(H,d)H\setminus S_{(H,d)} with |C|>34|V(H)||C|>\frac{3}{4}|V(H)|. Lemma 2 guarantees that, for every vertex vCv\in C, both the in-ball and out-ball of radius d4\frac{d}{4} centered at vv in H0H_{\geq 0} contain more than |V(H)|2\frac{|V(H)|}{2} vertices. Let u,vCu,v\in C. Since both the out-ball of radius d4\frac{d}{4} centered at uu and the in-ball of radius d4\frac{d}{4} centered at vv each contain more than |V(H)|2\frac{|V(H)|}{2} vertices, their intersection must be non-empty. Therefore, there exists wV(H)w\in V(H) such that there exists a path from uu to ww of length at most d4\frac{d}{4} in H0H_{\geq 0}, and a path from ww to vv of length at most d4\frac{d}{4} in H0H_{\geq 0}. By concatenating these two paths, we obtain a path from uu to vv of length at most d2\frac{d}{2} in H0H_{\geq 0}. Since H0G0H_{\geq 0}\subseteq G^{\prime}_{\geq 0}, this result extends to G0G^{\prime}_{\geq 0}. Therefore, the diameter of CC is at most d2\frac{d}{2} in H0H_{\geq 0} (and in G0G^{\prime}_{\geq 0}), as desired. ∎

Claim 7.

Let (H,d)(H,d) be any node in the decomposition tree with d<d0d<d_{0}. Then, with high probability, V(H)V(H) has diameter at most dd in G0G^{\prime}_{\geq 0}.

Proof.

Since (H,d)(H,d) is not the root, HH is a strongly connected component (SCC) of its parent HH^{\prime}. If V(H)>34|V(H)|V(H)>\frac{3}{4}|V(H^{\prime})|, then by Claim 6, V(H)V(H) has diameter at most dd in H0H_{\geq 0}, and hence in G0G^{\prime}_{\geq 0}. Otherwise, its parent node (H,d)(H^{\prime},d) has the same diameter parameter d<d0d<d_{0}. By induction, V(H)V(H^{\prime}) has diameter at most dd in G0G^{\prime}_{\geq 0}. Since V(H)V(H) is a subset of V(H)V(H^{\prime}), it also has diameter at most dd in G0G^{\prime}_{\geq 0}. Therefore, in both cases, V(H)V(H) has diameter at most dd in G0G^{\prime}_{\geq 0}, as desired. ∎

Claim 8.

Let (H,d)(H,d) be any node in the decomposition tree with d=d0d=d_{0}. Then, for all simple paths PP in HH with wH(P)0w_{H}(P)\leq 0, we have wH0(P)dw_{H_{\geq 0}}(P)\leq d.

Proof.

Let negH(P)0\text{neg}_{H}(P)\leq 0 denote the total negative weight (i.e., sum of negative-weight edges) of PP in HH. For a simple path PP in HH with wH(P)0w_{H}(P)\leq 0, each negative-weight edge in HH has weight at least W/2-W/2, and PP contains at most |V(H)|n\lvert V(H)\rvert\leq n edges. Therefore, negH(P)W/2n=d0\text{neg}_{H}(P)\geq-W/2\cdot n=-d_{0}. In H0H_{\geq 0}, all negative-weight edges are replaced with edges of weight 0. Hence, the weight of PP in H0H_{\geq 0} is given by wH0(P)=wH(P)+|negH(P)|w_{H_{\geq 0}}(P)=w_{H}(P)+\lvert\text{neg}_{H}(P)\rvert. Substituting wH(P)0w_{H}(P)\leq 0 and |negH(P)|W/2n=d\lvert\text{neg}_{H}(P)\rvert\leq W/2\cdot n=d, we find wH0(P)dw_{H_{\geq 0}}(P)\leq d, as desired. ∎

Claim 9.

Let (H,d)(H,d) be a node in the decomposition tree with d<d0d<d_{0}. With high probability, if there exists a path PP in HH such that wH(P)0w_{H}(P)\leq 0 but wH0(P)>dw_{H_{\geq 0}}(P)>d, then concatenating PP with a shortest path PP^{\prime} in G0G^{\prime}_{\geq 0} from the end of PP back to its start produces a negative-weight cycle in GG. In particular, if GG has no negative-weight cycles, then for all (potentially non-simple) paths PP in HH with wH(P)0w_{H}(P)\leq 0, we have wH0(P)dw_{H_{\geq 0}}(P)\leq d.

Proof.

Suppose there exists a path PP in HH such that wH(P)0w_{H}(P)\leq 0 but wH0(P)>dw_{H_{\geq 0}}(P)>d. Let negH(P)\text{neg}_{H}(P) denote the total negative weight of PP in HH. The weight of PP in H0H_{\geq 0} is given by wH0(P)=wH(P)+|negH(P)|w_{H_{\geq 0}}(P)=w_{H}(P)+\lvert\text{neg}_{H}(P)\rvert. Since wH(P)0w_{H}(P)\leq 0 and wH0(P)>dw_{H_{\geq 0}}(P)>d, it follows that |negH(P)|>d\lvert\text{neg}_{H}(P)\rvert>d. For each negative-weight edge ee in HH, its weight in GG is wG(e)=wH(e)W/2wH(e)|wH(e)|w_{G}(e)=w_{H}(e)-W/2\leq w_{H}(e)-|w_{H}(e)|, so the weight of PP in GG is wG(P)wH(P)|negH(P)|w_{G}(P)\leq w_{H}(P)-\lvert\text{neg}_{H}(P)\rvert. Substituting wH(P)0w_{H}(P)\leq 0 and |negH(P)|>d\lvert\text{neg}_{H}(P)\rvert>d, we find wG(P)<dw_{G}(P)<-d. By Claim 7, V(H)V(H) has diameter at most dd in G0G^{\prime}_{\geq 0}, so the shortest path PP^{\prime} in G0G^{\prime}_{\geq 0} from the end of PP back to its start satisfies wG0(P)dw_{G^{\prime}_{\geq 0}}(P^{\prime})\leq d. Since edge weights can only be smaller in GG, we also have wG(P)dw_{G}(P^{\prime})\leq d. Combining PP and PP^{\prime} forms a cycle C=P+PC=P+P^{\prime} in GG with wG(C)=wG(P)+wG(P)<d+d=0w_{G}(C)=w_{G}(P)+w_{G}(P^{\prime})<-d+d=0, so CC is a negative-weight cycle. ∎

Claim 10.

Let (H,d)(H,d) be a non-leaf node in the decomposition tree. Then, for any (potentially non-simple) path PP in HH with wH0(P)dw_{H_{\geq 0}}(P)\leq d, the number of edges of PP inside S(H,d)S_{(H,d)} (counting multiplicity) has expectation at most O(logn)O(\log n).

Proof.

Follows directly from Lemma 2. ∎

We now proceed to analyze the runtime and correctness of the Scale algorithm by considering whether HH contains a negative cycle. Below, let nH=|V(H)|n_{H}=|V(H)| and mH=|E(H)|m_{H}=|E(H)| denote the number of vertices and edges in HH.

Lemma 11.

Consider a node (H,d)(H,d), and suppose HH does not contain a negative-weight cycle. Then, BellmanFordDijkstra(H,ϕ)(H,\phi) runs in expected time O((mH+nHloglognH)logn)O\left((m_{H}+n_{H}\log\log n_{H})\log n\right).

Proof.

There are two cases to consider:

Case 1: For each vertex vV(H)v\in V(H), there exists a shortest path to vv of weight at most dd in H0H_{\geq 0}. In this case, the shortest path PP to vv with wH0(P)dw_{H_{\geq 0}}(P)\leq d has an expected O(logn)O(\log n) edges inside S(H,d)S_{(H,d)} by Claim 10. Since HϕH_{\phi} has non-negative weight edges outside of S(H,d)S_{(H,d)}, we have 𝔼[ηH,ϕ(v)]O(logn)\mathbb{E}[\eta_{H,\phi}(v)]\leq O(\log n) for the parameter ηH,ϕ\eta_{H,\phi} defined in Lemma 3. By Lemma 3, BellmanFordDijkstra runs in expected time O(v(degH(v)+loglogn)ηH,ϕ(v)),O(\sum_{v}(\deg_{H}(v)+\log\log n)\cdot\eta_{H,\phi}(v)), which has expectation O((mH+nHloglognH)logn)O((m_{H}+n_{H}\log\log n_{H})\log n) since 𝔼[ηH,ϕ(v)]O(logn)\mathbb{E}[\eta_{H,\phi}(v)]\leq O(\log n) for all vV(H)v\in V(H). Note that BellmanFordDijkstra can still terminate early and output a negative-weight cycle in GG, but that only speeds up the running time.

Case 2: For some vertex vV(H)v\in V(H), every shortest path to vv has weight more than dd in H0H_{\geq 0}. By Claim 9, this implies the existence of a negative-weight cycle in GG. Among all shortest paths to vv, let QQ be one minimizing wH0(Q)w_{H_{\geq 0}}(Q), which is still greater than dd. Take the longest prefix QQ^{\prime} of QQ with weight at most dd in H0H_{\geq 0}. Since wH0(Q)dw_{H_{\geq 0}}(Q^{\prime})\leq d, the number of edges of QQ^{\prime} inside S(H,d)S_{(H,d)} has expectation O(logn)O(\log n) by Claim 10. Let Q′′Q^{\prime\prime} be the path QQ^{\prime} concatenated with the next edge in QQ, so that wH0(Q′′)>dw_{H_{\geq 0}}(Q^{\prime\prime})>d and the number of edges of Q′′Q^{\prime\prime} inside S(H,d)S_{(H,d)} still has expectation O(logn)O(\log n). Since Q′′Q^{\prime\prime} is a prefix of shortest path QQ, it is also a shortest path. Let uV(H)u\in V(H) be the endpoint of Q′′Q^{\prime\prime}, and let ii be the number of iterations of BellmanFordDijkstra before di(u)=wH(Q′′)d_{i}(u)=w_{H}(Q^{\prime\prime}), so that ii has expected value O(logn)O(\log n). After ii iterations, BellmanFordDijkstra finds a shortest path PP ending at uu with wH(P)=di(u)=wH(Q′′)w_{H}(P)=d_{i}(u)=w_{H}(Q^{\prime\prime}). Moreover, wH0(P)wH0(Q′′)w_{H_{\geq 0}}(P)\geq w_{H_{\geq 0}}(Q^{\prime\prime}) since otherwise, replacing the prefix Q′′Q^{\prime\prime} of QQ by PP results in a shortest path to vv of lower weight in H0H_{\geq 0}, contradicting the assumption on QQ. It follows that after an expected O(logn)O(\log n) iterations of BellmanFordDijkstra, a path PP is found with wH(P)0w_{H}(P)\leq 0 and wH0(P)>dw_{H_{\geq 0}}(P)>d, and the algorithm terminates with a negative-weight cycle. The runtime is O((mH+nHloglognH)i)O((m_{H}+n_{H}\log\log n_{H})\cdot i), which has expectation O((mH+nHloglognH)logn)O((m_{H}+n_{H}\log\log n_{H})\log n). ∎

Lemma 12.

Consider a node (H,d)(H,d), and suppose HH contains a negative-weight cycle. Then, BellmanFordDijkstra(H,ϕ)(H,\phi) runs in expected time O((mH+nHloglognH)logn)O\left((m_{H}+n_{H}\log\log n_{H})\log n\right).

Proof.

There are two cases to consider:

Case 1: HH contains a negative-weight cycle consisting entirely of non-positive-weight edges. Since Decompose only removes positive-weight edges, such a cycle remains intact throughout the decomposition and persists in one of the leaf nodes. A negative-weight edge from this cycle is found in this leaf node, and the algorithm computes a negative-weight cycle and terminates early. In particular, the node (H,d)(H,d) is never processed.

Case 2: All negative-weight cycles in HH include at least one positive-weight edge. This case is the most subtle and requires carefully defining a reference path QQ.

Define M=(d+1)|V(H)|WM=-(d+1)\cdot|V(H)|\cdot W. We first claim that any (potentially non-simple) path in HH of weight at most MM in HH must have weight exceeding dd in H0H_{\geq 0}. Given such a path, we first remove any cycles on the path of non-negative weight in HH. The remaining path still has weight at most M=(d+1)|V(H)|WM=-(d+1)\cdot|V(H)|\cdot W, so it must have at least (d+1)|V(H)|(d+1)\cdot|V(H)| edges, which means it can be decomposed into at least d+1d+1 negative-weight cycles, each with at least one positive-weight edge in H0H_{\geq 0}. It follows that the path has weight at least d+1d+1 in H0H_{\geq 0}, concluding the claim.

Among all paths of weight at most MM in HH, let QQ be one with minimum possible weight in H0H_{\geq 0}, which must be greater than dd. Take the longest prefix QQ^{\prime} of QQ with weight at most dd in H0H_{\geq 0}. Since wH0(Q)dw_{H_{\geq 0}}(Q^{\prime})\leq d, the number of edges of QQ^{\prime} inside S(H,d)S_{(H,d)} has expectation O(logn)O(\log n) by Claim 10. Let Q′′Q^{\prime\prime} be the path QQ^{\prime} concatenated with the next edge in QQ, so that wH0(Q′′)>dw_{H_{\geq 0}}(Q^{\prime\prime})>d and the number of edges of Q′′Q^{\prime\prime} inside S(H,d)S_{(H,d)} still has expectation O(logn)O(\log n). Let uV(H)u\in V(H) be the endpoint of Q′′Q^{\prime\prime}, and let ii be the number of iterations of BellmanFordDijkstra before di(u)wH(Q′′)d_{i}(u)\leq w_{H}(Q^{\prime\prime}), so that ii has expected value O(logn)O(\log n). After ii iterations, BellmanFordDijkstra finds a path PP ending at uu with wH(P)=di(u)wH(Q′′)w_{H}(P)=d_{i}(u)\leq w_{H}(Q^{\prime\prime}). Moreover, wH0(P)wH0(Q′′)w_{H_{\geq 0}}(P)\geq w_{H_{\geq 0}}(Q^{\prime\prime}) since otherwise, replacing the prefix Q′′Q^{\prime\prime} of QQ by PP results in a path of lower weight in H0H_{\geq 0} and of weight at most MM in HH, contradicting the assumption on QQ. It follows that after an expected O(logn)O(\log n) iterations of BellmanFordDijkstra, a path PP is found with wH(P)0w_{H}(P)\leq 0 and wH0(P)>dw_{H_{\geq 0}}(P)>d, and the algorithm terminates with a negative-weight cycle. The runtime is O((mH+nHloglognH)i)O((m_{H}+n_{H}\log\log n_{H})\cdot i), which has expectation O((mH+nHloglognH)logn)O((m_{H}+n_{H}\log\log n_{H})\log n). ∎

We can now restate and prove Theorem 5. See 5

Proof.

We first consider the decomposition phase. For each node (H,d)(H,d), the decomposition takes expected time O((mH+nHloglognH)logn)O((m_{H}+n_{H}\log\log n_{H})\log n) by Lemma 2. At each level of the decomposition tree, the total number of edges and vertices across all nodes is bounded by mm and nn, respectively, so the expected runtime per level is O((m+nloglogn)logn)O((m+n\log\log n)\log n). With O(logn)O(\log n) levels in the decomposition tree, the total expected runtime is O((m+nloglogn)log2n)O((m+n\log\log n)\log^{2}n).

For processing each node (H,d)(H,d), Lemma 4 adjusts ϕ\phi in O(nH+mH)O(n_{H}+m_{H}) time, and Lemmas 11 and 12 establish an expected runtime of O((mH+nHloglognH)logn)O((m_{H}+n_{H}\log\log n_{H})\log n) for BellmanFordDijkstra. There may be an additional O(m+nloglogn)O(m+n\log\log n) time to output a negative-weight cycle, but this only happens once. Again, summing over all nodes (H,d)(H,d), the total expected runtime is O((m+nloglogn)log2n)O((m+n\log\log n)\log^{2}n).

To convert distances in GG^{\prime} into a reweighted graph GϕG_{\phi} with edge weights at least W/2-W/2, we note that setting ϕ\phi as the distances in GG^{\prime} makes GϕG^{\prime}_{\phi} non-negative. Since wG(e)=wG(e)+W/2w_{G^{\prime}}(e)=w_{G}(e)+W/2 for all eEe\in E, it follows that wGϕ(e)=wGϕ(e)wG(e)+wG(e)W/2w_{G_{\phi}}(e)=w_{G^{\prime}_{\phi}}(e)-w_{G^{\prime}}(e)+w_{G}(e)\geq-W/2, as desired. ∎

References

  • [BCF23] Karl Bringmann, Alejandro Cassis, and Nick Fischer. Negative-weight single-source shortest paths in near-linear time: Now faster! In 2023 IEEE 64th Annual Symposium on Foundations of Computer Science (FOCS), pages 515–538. IEEE, 2023.
  • [BNW22] Aaron Bernstein, Danupon Nanongkai, and Christian Wulff-Nilsen. Negative-weight single-source shortest paths in near-linear time. In 2022 IEEE 63rd annual symposium on foundations of computer science (FOCS), pages 600–611. IEEE, 2022.
  • [FHL+25] Nick Fischer, Bernhard Haeupler, Rustam Latypov, Antti Roeyskoe, and Aurelio Sulser. A simple parallel algorithm with near-linear work for negative-weight single-source shortest paths. In Symposium on Simplicity in Algorithms (SOSA), 2025.
  • [Gol95] Andrew V Goldberg. Scaling algorithms for the shortest paths problem. SIAM Journal on Computing, 24(3):494–504, 1995.
  • [Joh77] Donald B Johnson. Efficient algorithms for shortest paths in sparse networks. Journal of the ACM (JACM), 24(1):1–13, 1977.