Knight problem using Dijkstra's shortest path algorithm