hdu_1856_More is better_201403091720
More is better
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 11893 Accepted Submission(s): 4402
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.
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 <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX 10000010 using namespace std; int pre[MAX],s[MAX]; int find(int x)
{
int i,t,r;
r=x;
while(r!=pre[r])
r=pre[r];
while(x!=r)
{
i=pre[x];
pre[x]=r;
x=i;
}
return r;
}
int main()
{
int i,n;
while(scanf("%d",&n)!=EOF)
{
int i,j,k,a,b,t=,pa,pb,max=;
memset(pre,,sizeof(pre));
memset(s,,sizeof(s));
if(n==)
{
printf("1\n");
continue;
}
for(i=;i<MAX;i++)
{
pre[i]=i;
s[i]=; //开始时数量都为1,根节点为自己
}
for(i=;i<n;i++)
{
scanf("%d %d",&a,&b);
if(a>t) t=a;
if(b>t) t=b;
pa=find(a);pb=find(b);
//printf("%d %d\n",pa,pb);
if(pa!=pb)
{
pre[pb]=pa;
s[pa]+=s[pb]; //合并集合中元素个数
}
}
for(i=;i<=t;i++)
{
if(s[i]>max)
max=s[i];
}
printf("%d\n",max);
}
return ;
}
hdu_1856_More is better_201403091720的更多相关文章
随机推荐
- PCB 录屏工具Screen2Exe GifCam ScreenToGif
我们完成的软件作品后,需要向客户或领导演示软件功能介绍,这里力推3款录屏工具 一.Screen2Exe工具,录制exe视频文件 下载地址 http://pcbren.cn/ShareFiles/Sc ...
- E20170626-hm
authenticate vt. 认证,证明是真实的.可靠的或有效的; 鉴定,使生效; author n. 作者; 著作家; 创造者; 发起人;
- [Swift通天遁地]五、高级扩展-(4)快速生成Invert、Mix、Tint、Shade颜色及调整饱和度阶
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- NHibernate学习(零)-本次学习遇到的错误汇总
问题一: "System.TypeInitializationException"类型的未经处理的异常在 KimismeDemo.exe 中发生 其他信息: "NHibe ...
- wait、notify、notifyAll实现线程间通信
在Java中,可以通过配合调用Object对象的wait()方法和notify()方法或notifyAll()方法来实现线程间的通信.在线程中调用wait()方法,将阻塞等待其他线程的通知(其他线程调 ...
- photoshop制作古风画
效果图: 素材结构: 前期准备: 素材准备,我的素材包括:印章.花束.二次元妹纸,背景图片. 软件准备,用的软件是 photoshop CS6. 把二次元妹纸拖入photoshop,把她抠出来,Ctr ...
- React Native常用组件在Android和IOS上的不同
React Native常用组件在Android和IOS上的不同 一.Text组件在两个平台上的不同表现 1.1 height与fontSize 1.1.1只指定font,不指定height 在这种情 ...
- [Android]有关外部链接唤醒App需要注意的坑
移动互联网发展到今天,一个移动app需要和各种各样的外部链接关联,它不再仅仅从手机的桌面启动,更多的将会从其他的应用.浏览器链接.短信.二维码或者微信分享等渠道启动,这里涉及到的是各种各样的营销渠道和 ...
- 一个有趣的 ”Validation of viewstate MAC failed” 错误的发现和解决
在ASP.NET里面,View State使用较为广泛.它作为一个隐藏字段,可以帮助服务端”记住“客户端的改变,这样客户端 收到服务器对PostBack的响应后,仍然可以展现在PostBack之前设定 ...
- HDU_1063_Exponentiation_大数
Exponentiation Time Limit: 2000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...