An implementation of Dijkstra's algorithm.