pub fn johnson(g: &Graph) -> Result<AllPairsShortestPaths, ErrorsJSL>Expand description
Johnson’s algorithm (SciPy’s johnson), O(V E log V), better than Floyd-Warshall on sparse
graphs and allowing negative edges. Bellman-Ford from an added vertex joined to every vertex
by a zero edge gives potentials h with w(u, v) + h(u) − h(v) ≥ 0; Dijkstra from every
vertex on these reweighted edges, which keeps shortest paths shortest, then gives the
distances d'(u, v) − h(u) + h(v). Errors on a negative cycle (any negative edge of an
undirected graph is one).