Shortest Path Problem Leetcode Python Pandas