Fixed Dijkstra's algorithm and its output