Implementation of Prim's Algorithm for MST