Replaced Prim's algorithm with Dijkstra's algorithm