Ich bin nicht 100% zuversichtlich, damit zu arbeiten, aber mir wurde ein Beispiel gegeben, das ich hier zu vereinfachen versuche. Ich denke, es ist am einfachsten, wenn Sie einfach mit ganzen Zahlen von 0 bis n-1 arbeiten können, die entweder im selben Satz sind oder nicht.
#include <iostream>
#include <boost/pending/disjoint_sets.hpp>
#include <vector>
typedef boost::disjoint_sets_with_storage<> Uf;
std::vector<pair<int,int>> same_set;
// fill the vector with number pairs between 0 and n-1 where
// n is the number of unique elements in the set
// ...
int n = ...; // n is the number of unique set elements
Uf union_find_set(n); // creates the structure with numbers 0 to n-1
// in seperate sets. -> one set is for 0, one set for 1, ...
for (auto same : same_set) {
union_find_set.union_set(same.first, same.second);
}
// union_find_set now contains sets with the numbers
// 0 to n-1 according to which sets should be combined
// given in the vector same_set.
// check whether two elements are in the same set, i.e. 0 and 2:
std::cout << union_find_set.find_set(0, 2);
Sie können feststellen, was Sie hier suchen [http://stackoverflow.com/questions/4134703/understanding-boostdisjoint-sets](http://stackoverflow.com/questions/4134703/understanding-boostdisjoint -Sets) – Greg
Ich mochte diese Implementierung nie. Für alle meine Bedürfnisse verwende ich meine eigene Implementierung mit Liste und ungeordneter Karte. – Arunmu
@Greg Danke, aber nein, es ist nicht die gleiche Schnittstelle –