The loop order in Floyd-Warshall is critical: must be the outer loop. Why?
Because paths using vertices depend on paths using . If you loop or first, you break the dependency order. Always write: for k, for i, for j. Any other order gives wrong answers. This is not a performance improvement, it affects correctness. Get the order wrong and you get incorrect shortest paths.