improved speed of kruskal() method