A Polynomial-Time Algorithm for the Next-to-Shortest Path Problem on Positively Weighted Directed Graphs
Kuowen Chen, Nicole Wein, Yiran Zhang
TL;DR
This work resolves the long-standing open question of whether a next-to-shortest $s\to t$ path can be found in polynomial time for directed graphs with positive edge weights by introducing a reduction to $(s,t)$-layered graphs and proving a central Key Lemma. The approach decomposes any not-shortest $s\to t$ path into a middle subpath flanked by two forward-disjoint paths, enabling a construction that combines two forward paths with a shortest middle segment to yield a next-to-shortest path. The authors develop a layered-graph algorithm NextSP-Layered, with a complexity bound of $O(|V|^4|E|^3\log |V|)$, and provide a reduction pipeline through $(s,t)$-straight graphs to layered graphs, ensuring polynomial-time solvability for all positively weighted directed graphs. This advances the theory of near-shortest paths and provides a practical framework for computing strictly second-shortest paths in directed, positively weighted networks. The results have implications for network design and routing where near-optimal alternatives are required efficiently, and they settle a nearly 30-year-old open problem in the affirmative under $P\neq NP$-style assumptions.
Abstract
Given a graph and a pair of terminals $s$, $t$, the next-to-shortest path problem asks for an $s\!\to \!t$ (simple) path that is shortest among all not shortest $s\!\to \!t$ paths (if one exists). This problem was introduced in 1996, and soon after was shown to be NP-complete for directed graphs with non-negative edge weights, leaving open the case of positive edge weights. Subsequent work investigated this open question, and developed polynomial-time algorithms for the cases of undirected graphs and planar directed graphs. In this work, we resolve this nearly 30-year-old open problem by providing an algorithm for the next-to-shortest path problem on directed graphs with positive edge weights.
