UVA 10608Friends【并查集】
来源:互联网 发布:js获取节点的方法 编辑:程序博客网 时间:2024/05/16 19:09
题目链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1549
题意:给定n个人m种朋友关系,求最大朋友圈的人数。裸并查集
代码:
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <stack>#include <queue>using namespace std;int f[30010];int c[30010];int find(int x){ if (f[x] == x) return x; else return f[x] = find(f[x]);}int main(){ int t; int n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { f[i]=i;c[i]=1; } int a,b; int ans = -1; for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); int t1 = find(a); int t2 = find(b); if (t1 != t2) { f[t2] = t1; c[t1] += c[t2]; ans = max(ans,c[t1]); } } printf("%d\n",ans); } 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 10608Friends【并查集】
- UVA---10608-Friends(并查集)
- UVa - 10608 Friends (并查集)
- Friends+uva+并查集
- UVA - 10608 Friends 并查集水题
- UVA 10806 Friends 并查集
- Friends(并查集)
- Friends--并查集
- uva 10608 Friends(求并查集集合中元素个数)
- iOS推送过程详解
- HDU 4730 We Love MOE Girls
- OpenCV学习之路
- STL之set详解
- msl、ttl及rtt的区别—— TCP控制字段标志
- UVA 10608Friends【并查集】
- VS2010发布网站失败解决办法
- 120. Triangle
- 跟我从零学Java
- Android插件化开发之OpenAtlas初体验
- 快快快!27个提升效率的iOS开源库推荐
- 测试用例
- C++ 预处理、const与sizeof 知识点 小结
- Linux - 设置Centos控制台模式的分辨率