clustering using Prim and Kruskal algorithm