HDU1856_More is better
来源:互联网 发布:单身狗公仔淘宝 编辑:程序博客网 时间:2024/06/05 23:01
并查集水题,题意将直接或间接是朋友的放在一个房间,问一共需要多少房间,代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAX = 10000001;int father[MAX], num[MAX];int n;void init(){ for(int i=0; i<MAX; ++i) { father[i] = i; num[i] = 1; }}int fin(int x){ return x==father[x] ? x : father[x]=fin(father[x]);}void comb(int a, int b){ int pa = fin(a), pb = fin(b); if(pa != pb) { father[pa] = pb; num[pb] += num[pa]; num[pa] = 0; }}void per(){ int Max = 0; for(int i=0; i<MAX; ++i) { if(Max < num[i]) Max = num[i]; } cout << Max << endl;}int main(){ while(~scanf("%d", &n)) { int a, b, c = n; init(); while(c--) { scanf("%d%d", &a, &b); comb(a, b); } per(); } return 0;}
0 0
- HDU1856_More is better
- English is better and better
- HDOJ More is better
- HDU2929:Bigger is Better
- Worse is Better
- hdu More is better
- HDOJ1856More is better
- More is better
- HDU1856:More is better
- HDU1856--More is better
- hdu1856-More is better
- HDU1856:More is better
- hdu1856 More is better
- H - More is better
- More is better
- More is better
- More is better
- More is better
- MySQL创建用户与授权方法
- RFID第一次作业第三题
- 101-开发技巧和一些常见的问题(1)
- MFC添加右键菜单
- 黑马程序员——Java编程语言学习总结 – IO流
- HDU1856_More is better
- 向设备下载镜像提示有未知符号的调试方式
- VS在可执行文件中调试dll函数
- 一个简单的布局管理器测试
- 深入浅出MyBatis-快速入门
- ios xmpp研究探索:获取消息列表
- ubuntu图下安装软件出现You might want to run 'apt-get -f install' to correct these解决
- jQuery css3圆形倒数秒计时器代码
- COM组件返回二维数组供javascript和客户端使用