Implemented Question 3 (Prim's minimum spanning tree algorithm)