Implements Dijkstra's and Kruskal's algorithms given node maps.