Persistent Union-Find datastructure and algorithm