hdu-1856-More is better
More is better
Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 24825    Accepted Submission(s): 8911
Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
1 2
3 4
5 6
1 6
4
1 2
3 4
5 6
7 8
A and B are friends(direct or indirect), B and C are friends(direct or indirect), then A and C are also friends(indirect). In the first sample {1,2,5,6} is the result. In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX=;
int f[MAX],v[MAX];
int find(int n)
{
if(n!=f[n])
f[n]=find(f[n]);
return f[n];
} int main()
{ int n;
while(cin>>n)
{
for(int i=;i<MAX;i++)
{f[i]=i;v[i]=;}
int a,b;
int t=;
for(int i=;i<n;i++)
{scanf("%d%d",&a,&b);
a=find(a);
b=find(b);
if(a!=b)
{f[a]=b;v[b]+=v[a];t=max(t,v[b]);}
}
cout<<t<<endl;
}
return;
}
hdu-1856-More is better的更多相关文章
- 简单并查集 -- HDU 1232  UVALA 3644 HDU 1856
		并查集模板: #include<iostream> using namespace std; ],x,y; ]; //初始化 x 集合 void init(int n) { ; i< ... 
- HDU 1856 More is better(并查集+离散化)
		题目地址:HDU 1856 水题.因为标号范围太大,而数据数仅仅有10w,所以要先进行离散化.然后就是裸的并查集了. 代码例如以下: #include <iostream> #includ ... 
- HDU(1856),裸的带权并查集
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 题意:朋友圈问题,A和B是朋友,B和C是朋友则A和C也是朋友,依次类推,题目的意思就是求最大的朋 ... 
- HDU 1856
		http://acm.split.hdu.edu.cn/showproblem.php?pid=1856 对于这道题,主要就是让你求出有最多结点的树的树叶: 我们只要利用并查集的知识吧所输入的数据连接 ... 
- HDU 1856  More is better(并查集)
		http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ... 
- HDU  1856 并查集
		http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ... 
- hdu 1856 More is better (并查集)
		More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ... 
- HDU 1856 Brave Game(巴什博奕)
		十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻. 今天,大家选择 ... 
- Hdu 1856(离散化+并查集)More is better
		题意:一些人遵循朋友的朋友也是朋友原则,现在找出最大的朋友圈, 因为人的编号比较大,但是输入的数据最多是10w行,所以可得出最多也就20w人,所以可以进行一下离散化处理,这样数据就会毫无压力 //// ... 
- More is better(hdu 1856 计算并查集集合中元素个数最多的集合)
		More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ... 
随机推荐
- [javaweb]Java过滤器与包装设计模式的实用案例.
			在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ... 
- java学习笔记--this 关键字的理解
			彻底理解this 关键字的含义 this关键字再java里面是一个我认为非常不好理解的概念,:)也许是太笨的原因 this 关键字的含义:可为以调用了其方法的那个对象生成相应的句柄. 怎么理解这段话呢 ... 
- 更新日志 - fir.im 新版优化上线
			经过这段时间的用户反馈收集和新版本的功能调研,我们对 fir.im Rio 上传下载.应用管理再次做了调整优化.感谢之前内测用户的反馈与建议.目前 fir.im Rio 新版已正式上线,主要优化有以下 ... 
- javascript原型对象prototype
			“我们创建的每一个函数都有一个prototype(原型)属性,这个属性是一个指针,指向一个对象,而这个对象的用途是包含可以由特定类型的所有实例共享的属性和方法.” 引用类型才具有prototype属性 ... 
- SQLServer性能分析
			SQLServer性能分析 当数据库出现性能问题,应用出现运行缓慢的时候,下面这个东东能让你如获至宝 create table #sp_who2 ( SPID int ,status varchar( ... 
- python开启简单webserver
			python开启简单webserver linux下面使用 python -m SimpleHTTPServer 8000 windows下面使用上面的命令会报错,Python.Exe: No Mod ... 
- java中IO流相关知识点
			(一) 下边使用outputStream字节输出流进行写操作 package zdbIO;import java.io.File;import java.io.FileNotFoundExceptio ... 
- agularJs 路由
			angularJs的路由方式: 先定义一个模板ng-app-->然后定义路由的规则(routeProvider)在服务config里-->然后通过不同的URL实现 到单页面加载的所需页面的 ... 
- 【WP8.1开发】认识后台任务
			在手机上,使用后台,不像电脑上那么随意,准确地讲嘛,在移动平台上,后台任务都有严格的限制.至于说为什么会有这么多限制,我估计初衷很明显——保证系统的性能不受某个或某几个应用的负面影响:另外就是出于安全 ... 
- 关于AJAX跨域调用ASP.NET MVC或者WebAPI服务的问题及解决方案
			作者:陈希章 时间:2014-7-3 问题描述 当跨域(cross domain)调用ASP.NET MVC或者ASP.NET Web API编写的服务时,会发生无法访问的情况. 重现方式 使用模 ... 
