C++ port of java union find algorithms from Algorithms 4th edition by Sedgwich and Wayne