Basic kruskal's algorithm