Finding the shortest path in a graph with Floude's method