UVa 10608 - Friends(并查集)
来源:互联网 发布:公司域名备案需要多久 编辑:程序博客网 时间:2024/06/12 01:30
题目:求最大的集合的元素个数。
分析:并查集简单题目。
AC代码
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int N = 30005;int pa[N], son[N];int n,m;void init() { for(int i = 0; i <= n; i++) { pa[i] = i; son[i] = 1; }}int find(int x) { if(x == pa[x]) return x; else return find(pa[x]);}void Union(int x,int y) { int r1 = find(x) , r2 = find(y); if(r1 == r2) return ; if(r1 < r2) { pa[r2] = r1; son[r1] += son[r2]; }else { pa[r1] = r2; son[r2] += son[r1]; }}int main() { int T, x, y; scanf("%d", &T); while(T--) { scanf("%d%d",&n,&m); init(); while(m--) { scanf("%d%d", &x, &y); Union(x,y); } int Max = -INF; for(int i = 1; i <= n; i++) { Max = max(Max, son[i]); } printf("%d\n",Max); } return 0;}
0 0
- uva 10608 - Friends(并查集)
- uva 10608 - Friends (并查集)
- UVa 10608 - Friends(并查集)
- UVA - 10608-Friends(并查集)
- UVa 10608 - Friends(并查集)
- uva 10608 Friends(并查集)
- UVA---10608-Friends(并查集)
- UVA 10608 - Friends (并查集)
- UVA 10608 Friends 并查集
- UVA 10608 Friends 并查集
- UVA 10608Friends【并查集】
- UVa - 10608 Friends (并查集)
- Friends+uva+并查集
- UVA - 10608 Friends 并查集水题
- UVA 10806 Friends 并查集
- Friends(并查集)
- uva 10608 Friends(求并查集集合中元素个数)
- Friends(并查集)
- BZOJ2761 不重复数字
- 简单方便的大众型视频编辑器“编辑星”正式免费开放
- Android软件开发之获取通讯录联系人信息(二十九)
- Code[VS] 1029 遍历问题
- 简单方便的大众型视频编辑器“编辑星”正式免费开放
- UVa 10608 - Friends(并查集)
- 关于那些将要毕业的事
- ACM--steps--3.3.5--Robberies(01背包)
- hdu 1301 Jungle Roads 一个很水的题 AC率也可以知道了 但是题目很难理解啊 英语渣o(╯□╰)oKruskal算法
- 可伸缩多线程任务队列
- 《人是为了别人而活着》——爱因斯坦
- 简单方便的大众型视频编辑器“编辑星”正式免费开放
- Code[VS] 1979 第k个数
- acm2013