A version of Dijkstra's Algorithm