湖南十大龙头企业,seo优化推广招聘,网站开发流程包括哪几个步骤?,展馆设计案例http://acm.hdu.edu.cn/showproblem.php?pid1213 题意#xff1a; 这个问题的一个重要规则是#xff0c;如果我告诉你A知道B#xff0c;B知道C#xff0c;这意味着A#xff0c;B#xff0c;C知道对方#xff0c;所以他们可以留在一个桌子。例如#xff1a;如果我告诉你…http://acm.hdu.edu.cn/showproblem.php?pid1213 题意 这个问题的一个重要规则是如果我告诉你A知道BB知道C这意味着ABC知道对方所以他们可以留在一个桌子。例如如果我告诉你A知道BB知道CD知道E所以ABC可以留在一个桌子中DE必须留在另一个桌子中。所以Ignatius至少需要2个桌子。 思路 并查集模板题。 #includeiostream
using namespace std;int p[1005];int find(int x)
{return p[x] x ? x : find(p[x]);
}void Unions(int x, int y)
{p[x] y;
}int main()
{//freopen(D:\\txt.txt, r, stdin);int T, a, b, n, m;cin T;while (T--){cin n m;for (int i 1; i n; i)p[i] i;for (int i 0; i m; i){cin a b;int x find(a);int y find(b);if (x ! y)Unions(x, y);}int ans 0;for (int i 1; i n;i)if (p[i] i) ans;cout ans endl;}return 0;
} 转载于:https://www.cnblogs.com/zyb993963526/p/6386359.html