* This file is a part of LEMON, a generic C++ optimization library
* Copyright (C) 2003-2008
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
#include <lemon/unionfind.h>
typedef UnionFindEnum<StdMap<int, int> > UFE;
void print(UFE const &ufe) {
cout << "Print the classes of the structure:" << endl;
for (UFE::ClassIt cit(ufe); cit != INVALID; ++cit) {
cout << " " << i << " (" << cit << "):" << flush;
for (UFE::ItemIt iit(ufe, cit); iit != INVALID; ++iit) {
cout << " " << iit << flush;
check(U.join(1,2) != -1,"Test failed.");
check(U.join(1,4) != -1,"Test failed.");
check(U.join(2,4) == -1,"Test failed.");
check(U.join(3,5) != -1,"Test failed.");
check(U.size(U.find(4)) == 3,"Test failed.");
check(U.size(U.find(5)) == 3,"Test failed.");
check(U.size(U.find(6)) == 1,"Test failed.");
check(U.size(U.find(2)) == 3,"Test failed.");
check(U.join(8,10) != -1,"Test failed.");
check(U.size(U.find(4)) == 3,"Test failed.");
check(U.size(U.find(9)) == 5,"Test failed.");
check(U.size(U.find(8)) == 5,"Test failed.");
check(U.size(U.find(10)) == 4,"Test failed.");
check(U.size(U.find(2)) == 2,"Test failed.");
check(U.size(U.find(4)) == 2,"Test failed.");
check(U.size(U.find(3)) == 1,"Test failed.");
check(U.size(U.find(2)) == 2,"Test failed.");
check(U.join(3,4) != -1,"Test failed.");
check(U.join(2,4) == -1,"Test failed.");
check(U.size(U.find(4)) == 3,"Test failed.");
check(U.size(U.find(3)) == 3,"Test failed.");
check(U.size(U.find(2)) == 3,"Test failed.");