Simple implementation of Dijkstra's algorithm.