Apply Dijkstra's algorithm (#708)