fix a problem of the shortestPath function