Shortest Path Problems Leetcode Python