Introduction: all-pairs shortest paths and negative cycles [00RP]

Recall that Dijkstra’s algorithm solves the single-source shortest path problem (i.e. it finds the shortest path from a single start vertex to every other vertex) for weighted, directed graphs, as long as all edge weights are positive. Today we will consider an algorithm to solve the all-pairs shortest path problem (that is, to find shortest paths between all possible pairs of vertices) on directed graphs with arbitrary (possibly negative) weights.

Of course, negative cycles can pose a problem: if there is a directed cycle whose total weight is negative, then we can keep decreasing the path weight forever by just going around the cycle. In that case “shortest” paths may not be well-defined. The algorithm we consider will also be able to detect this situation.