Implemented simple Kruskal's algorithm