A toy implementation of union-find and Kruskal's algorithm