Johnson shortest paths
Your task
Given a directed weighted graph with n nodes (0..n-1) and edges [u, v, w] where w may be negative, compute the shortest-path distances from a given source to every node using Johnson's reweighting technique (a virtual node with 0-weight edges to all, one Bellman-Ford pass to get potentials, then Dijkstra on the reweighted non-negative graph, then undo the reweighting). Return a list dist where dist[v] is the shortest distance from src to v, or -1 if v is unreachable; if the graph contains a negative cycle, return an empty list. Assume 1 <= n <= 300.
Examples
johnson_apsp_from_source(n: int, edges: list[list[int]], src: int) -> list[int]Example 1
Input
johnson_apsp_from_source(4, [[0, 1, 1], [1, 2, 2], [0, 2, 5], [2, 3, 1]], 0)Output
[0, 1, 3, 4]