[#81] Fix some edge cases in Dijkstra's algorithm