Floyd–Warshall algorithm implementation.