Shortest Path Problem Leetcode Python Coding