k-clustering using kruskal's algorithm