More is better hdu1856 并查集
来源:互联网 发布:搞基漫画软件 编辑:程序博客网 时间:2024/05/14 13:12
http://acm.hdu.edu.cn/showproblem.php?pid=1856
题意:老师想从10000000里面找尽可能多的学生帮他做项目,条件是这些人必须都认识。给n个关系,求最多有多少个人能帮助老师做项目。
因为数据量较大,如果不进行数据压缩的话就过不去。
#include <iostream>using namespace std;#define N 10000005int boy[N];int findfather(int n){if (boy[n]<0)return n;boy[n]=findfather(boy[n]);return boy[n];}int main(){#ifndef ONLINE_JUDGEfreopen("1856in.txt","r",stdin);#endifint n,a,b,i,min;while (scanf("%d",&n)!=EOF){for (i=1;i<N;i++)boy[i]=-1;for (i=0;i<n;i++){scanf("%d%d",&a,&b);a=findfather(a);b=findfather(b);if (a!=b){if (boy[a]<=boy[b]){boy[a]+=boy[b];boy[b]=a;}else {boy[b]+=boy[a];boy[a]=b;}}}min=0;for (i=1;i<N;i++)if (boy[i]<min)min=boy[i];printf("%d\n",-min);}return 0;}
- More is better hdu1856 并查集
- hdu1856 ,More is better,并查集
- Hdu1856 - More is better - 并查集
- HDU1856 More is better 并查集
- HDU1856 More is better 并查集
- hdu1856 More is better 并查集
- HDU1856 More is better(并查集)
- hdu1856 More is better 并查集
- hdu1856 More is better--并查集
- hdu1856 More is better 并查集
- HDU1856(More is better)—并查集+树
- hdu1856 More is better(并查集)
- hdu1856 More is better(并查集 )
- hdu1856 More is better (并查集)
- More is better--hdu1856(并查集)
- HDU1856 More is better(并查集)
- HDU1856 More is better(并查集)
- 【1】【并查集】HDU1856 More is better
- hdoj最大连续子序列 (简单dp)
- hdu 2767
- 【MFC/C++操作Excel】Excel篇
- QT源码之QT创建窗口程序、消息循环和WinMain函数
- PHP伪静态配置
- More is better hdu1856 并查集
- CenOS6.0 源码安装vsftpd 配置虚拟用户
- Graphics View柜架
- 独辟蹊径网络安装系列之Redhat衍生版重构初探[09年3月刊]
- 多路复用(select 群回发)
- [android] 通过xml文件设置控件的阴影效果
- win7 wifi 共享 设置方法
- 利用谷歌语法查找网站后台和数据库
- Jvmstat监控JVM内存