Implementation of Dijkstra's algorithm for finding least cost paths.