Implementation of Prim's Algorithm