Prims Algorithm in a Matrix