Implemented Prim's MST algorithm