accomplish Prim's algorithm