Dijkstra's algorithm implemented by Jani Lahtinen