Dynamic Programming Shortest Path Algorithm Python