floyd-warshall algo, fixing exceptions