fixed floyd-warshall, optimized it also a bit