本文整理汇总了C++中DisjointSet::getNumberOfComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::getNumberOfComponent方法的具体用法?C++ DisjointSet::getNumberOfComponent怎么用?C++ DisjointSet::getNumberOfComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DisjointSet
的用法示例。
在下文中一共展示了DisjointSet::getNumberOfComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
ifstream ifs;
if (argc != 2)
{
cout << getlonglong("1 1 1 1") << endl;
cout << getlonglong("1 0 1 0") << endl;
return -1;
}
ifs.open(argv[1]);
string str;
ifs >> N >> M;
getline(ifs, str);
vl G = vl(N);
DisjointSet ds = DisjointSet(N);
for (int i = 0; i < N; ++i)
{
std::getline(ifs, str);
G[i] = getlonglong(str);
}
sort(G.begin(), G.end());
unionEquals(G, ds, CmpByMask(-1));
/* find all nodes, which differ by single bit only */
for (int i = 0; i < M; ++i)
{
long long mask = ~(1LL << i);
sort(G.begin(), G.end(), CmpByMask(mask));
unionEquals(G, ds, CmpByMask(mask));
}
/* find all nodes, which differ by two bits */
for (int i = 0; i < M - 1; ++i)
{
for (int j = i + 1; j < M; ++j)
{
long long mask = ~((1LL << i) + (1LL << j));
sort(G.begin(), G.end(), CmpByMask(mask));
unionEquals(G, ds, CmpByMask(mask));
}
}
/* output how many clusters do we have */
cout << ds.getNumberOfComponent() << endl;
return 0;
}