Floyd Warshall algorithm to compute all pairs shortest paths. O(N^3) algorithm.