Shortest Path Leetcode Problems Python