terminate _dijkstra() when finding the end node