dist in floyd warshall is not the weight but 1/weight
adaptation of floyd warshall to our purposes