Prim's algorithm for computing minimum cost spanning tree