Shortest Path Problem Python