Shortest Path Algorithm Leetcode Python