HDU 1856 More is better (并查集)
来源:互联网 发布:java程序员电脑配置 编辑:程序博客网 时间:2024/05/20 11:25
题目连接:请戳这里。
题目大意及思路:就是找学生最多的那个集合。注意一点的是“or there is only one boy left.”
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<queue>#define N 10000000+10using namespace std;int f[N],num[N];void Init(int n){ for(int i=1;i<=n;i++) { f[i]=i; num[i]=1; }}int Find(int x){ return f[x]==x?x:f[x]=Find(f[x]);}void Merge(int a,int b){ int ra=Find(a),rb=Find(b); if(ra==rb) return ; else { f[rb]=ra; num[ra]+=num[rb]; }}int main(){ int m; while(scanf("%d",&m)==1) { Init(N); int n=0; for(int i=0;i<m;i++) { int a,b; scanf("%d %d",&a,&b); n=max(n,max(a,b)); Merge(a,b); } int Max=1; //当n=0时,答案应该是1~ for(int i=1;i<=n;i++) Max=max(Max,num[i]); printf("%d\n",Max); } return 0;}
0 0
- hdu 1856 More is better 并查集(二)
- hdu 1856 More is better(并查集)
- hdu 1856 More is better (并查集)
- HDU 1856 More is better(基础并查集)
- HDU 1856 More is better (并查集)
- HDU 1856 More is better (并查集)
- hdu 1856 More is better(并查集)
- hdu 1856 More is better(并查集)
- hdu 1856 More is better (并查集)
- HDU 1856 More is better(并查集)
- hdu 1856 More is better (并查集)
- 【HDU】-1856-More is better(并查集)
- HDU:1856 More is better(并查集+技巧)
- hdu 1856 More is better (并查集)
- HDU 1856 More is better(并查集)
- hdu 1856(并查集)More is better
- HDU-1856 More is better(并查集)
- hdu 1856 More is better(并查集基础)
- IOS线程数据篇10之Sqlite3数据库的使用
- Ubuntu防火墙设置
- Insert语句加/*+APPEND */在循环中单条提交对系统的影响分析
- windbg调试
- VC 判断CString字符串中各位是数字,大小写字母,符号,汉字
- HDU 1856 More is better (并查集)
- ios开发之app内启动用户评价
- C++ 指针和const限定符
- WV.3-动态链表-新结点总是链表头
- python 栈
- JSP中pageEncoding contentType 字符编码个人归纳总结
- mysql创建index索引
- onCreateOptionsMenu()方法
- SqlMap中中$与#的区别