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的更多相关文章
随机推荐
- JS/CSS 压缩的好处
1.减小了文件的体积 2.减小了网络传输量和带宽占用 3.减小了服务器的处理的压力 4.提高了页面的渲染显示的速度
- Codeforces 612D 前缀和处理区间问题
传送门:http://codeforces.com/problemset/problem/612/D (转载请注明出处谢谢) 题意: 给出数字n和k,n表示接下来将输入n个在x轴上的闭区间[li,ri ...
- 题解报告:hdu 1279 验证角谷猜想
Problem Description 数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五.六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数, ...
- IOS开发 键盘添加工具条 退出 上一项 下一项 简单实现
首先设置每个 UITextField 的 inputAccessoryView 为UIToolBar : 将所有的 textField 放入一个数组: 设置 UITextField UITextFie ...
- [ CQOI 2009 ] 中位数图
\(\\\) \(Description\) 给出\(N\)的一个全排列,统计该排列有多少个长度为奇数的连续子序列,中位数是\(B\). \(N\in [0,10^5]\),\(B\in [0,N]\ ...
- Python--10、生产者消费者模型
生产者消费者模型(★) 平衡生产线程和消费线程的工作能力来提高程序的整体处理数据的速度.程序中有两类角色:生产数据.消费数据实现方式:生产->队列->消费. 通过一个容器来解决生产者和消费 ...
- 1B课程笔记分享_StudyJams_2017
课程1B 概述 课程1B主要讲解了Android UI的ViewGroups(视图组).LinearLayout(线性布局).RelativeLayout(相对布局),Portrait Mode(竖屏 ...
- iOS开发中如何实现同步、异步、GET、POST等请求实操演示!
1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...
- 实例分割:MaskXRCnn 与Visual Genome数据集
一.VG数据集 机器学习领域的突破突然让计算机获得了以未曾有的高精度识别图像中物体的能力--几乎达到了让人惊恐的程度.现在的问题是机器是否还能更上层楼,学会理解这些图片中所发生的事件. Visual ...
- Vue动态创建组件方法
组件写好之后有的时候需要动态创建组件.例如: 编辑文章页面,正文是一个富文本编辑器,富文本编辑器是一个第三方的组件,点击添加章节的时候需要动态的创建一个富文本编辑器这个时候怎么处理呢. 富文本编辑器也 ...