本文整理汇总了C++中DisjointSet::findSet方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::findSet方法的具体用法?C++ DisjointSet::findSet怎么用?C++ DisjointSet::findSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DisjointSet
的用法示例。
在下文中一共展示了DisjointSet::findSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unionEquals
void unionEquals(vl & G, DisjointSet &ds, CmpByMask cmp)
{
for (uint i = 0; i < G.size() - 1; ++i)
{
/* if previous less than next */
if (cmp(G[i], G[i + 1]))
{
continue;
}
/* two adjacent nodes are equal */
/* check if they belong to different component and union them */
/* BUG: keep index in G */
if (ds.findSet(i) != ds.findSet(i + 1))
{
ds.unionNodes(i, i + 1);
}
}
}
示例2: main
int main(){
DisjointSet<int> s;
/*
* you fill in here to set up the disjoint set
*/
s.createSet(1);
s.createSet(2);
s.createSet(3);
s.createSet(4);
s.createSet(5);
s.createSet(6);
s.createSet(7);
s.createSet(8);
s.createSet(9);
s.unionSets(3,5);
s.unionSets(4,2);
s.unionSets(1,6);
s.unionSets(5,7);
s.unionSets(4,8);
s.unionSets(3,7);
s.unionSets(8,1);
assert(s.findSet(1) == s.findSet(6)); // 1 and 6 are connected.
assert(s.findSet(3) != s.findSet(6)); // 3 and 6 are not connected.
assert(s.findSet(1) == s.findSet(1)); // 1 and 1 are connected.
assert(s.findSet(3) == s.findSet(5)); // 3 and 5 are connected.
assert(s.findSet(3) != s.findSet(9)); // 3 and 9 are not connected.
cout<< "Done"<<endl;
}
示例3: main
int main() {
DisjointSet djset;
DisjointSet::NodePtr id[3];
id[0] = djset.makeSet(0);
id[1] = djset.makeSet(1);
id[2] = djset.makeSet(2);
djset.linkSets(id[0], id[1]);
djset.linkSets(id[1], id[2]);
DisjointSet::SetIdentifier t1 = djset.findSet(id[0]);
DisjointSet::SetIdentifier t2 = djset.findSet(id[2]);
}