Why it matters

Floyd-Warshall is standard APSP for dense. Simple + reliable.

Advertisement

The architecture

dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) for each intermediate k.

Triple nested loop.

Floyd-Warshall DPInitdirect edgesFor k = 1..Vallow via kResultshortest via anyAlso computes transitive closure by using OR instead of min
Floyd-Warshall algorithm.
Advertisement

How it works end to end

Path reconstruction: track predecessors.

Transitive closure: same algorithm with OR + AND.

Negative cycles: dist[i][i] < 0 for some i.