题目描述:
Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.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 roo
3 4
5 6
1 6
4
1 2m 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.
输入:
The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
输出:
The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep.
样例输入:
4
1 2
3 4
5 6
7 8
样例输出:
4
2


思路:在图中所有的连通分量中找出包含顶点最多的个数。继续使用并查集解决!

#include <iostream>
using namespace std; const int MAX = ;
int tree[MAX];
int counts[MAX]; int getRoot(int x)
{
if (tree[x] == -)
return x;
else
{
int tmp = getRoot(tree[x]);
tree[x] = tmp;
return tmp;
}
} int main()
{
int n;
int town1, town2;
int result;
while (cin >> n && n != )
{
for (int i = ; i < MAX; i++)
{
tree[i] = -;
counts[i] = ;
} result = ;
for (int i = ; i <= n; i++)
{
cin >> town1 >> town2;
town1 = getRoot(town1);
town2 = getRoot(town2);
if (town1 != town2)
{
tree[town1] = town2;
counts[town2] += counts[town1];
} } for (int i = ; i <= MAX; i++)
{
if (result < counts[i])
result = counts[i];
} cout << result << endl;
}
return ;
}

More is better-多多益善的更多相关文章

  1. 又一个opengl教程,多多益善

    http://ogldev.atspace.co.uk/index.html http://wiki.jikexueyuan.com/project/modern-opengl-tutorial/tu ...

  2. Web性能优化:图片优化

    程序员都是懒孩子,想直接看自动优化的点:传送门 我自己的Blog:http://cabbit.me/web-image-optimization/ HTTP Archieve有个统计,图片内容已经占到 ...

  3. 程序员装B指南

    一.准备工作 "工欲善其事必先利其器." 1.电脑不一定要配置高,但是双屏是必须的,越大越好,能一个横屏一个竖屏更好.一个用来查资料,一个用来写代码.总之要显得信息量很大,效率很高 ...

  4. ubuntu入门

    Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音.了解发音是有意义的,您不是第一个为此困惑的人,当然,也不会是最后一个:) 大多数的美国人读 ubun ...

  5. html5 canvas简易版捕鱼达人游戏源码

    插件描述:html5利用canvas写的一个js版本的捕鱼,有积分统计,鱼可以全方位移动,炮会跟着鼠标移动,第一次打开需要鼠标移出背景图,再移入的时候就可以控制炮的转动,因为是用的mouseover触 ...

  6. HTML5移动端图片左右切换动画

    插件描述:HTML5移动端图片左右切换动画 小海今天要给大家分享一款很不错的图片左右切换焦点图动画,并且支持移动端触摸滑动.功能上,这款HTML5图片播放器支持鼠标滑动.手机端触摸滑动以及自动播放.外 ...

  7. C# 正则表达式

    引用自:http://www.cnblogs.com/stg609/archive/2009/06/03/1492709.html 摘要:正则表达式(Regular Expressions),相信做软 ...

  8. Alamofire 的使用

    最近,AFNetworking 的作者Mattt Thompson提交了一个新的类似于 AFNetworking 的网络 基础库,并且是专门使用最新的 Swift 语言来编写的,名为:Alamofir ...

  9. 【详解】ERP、APS与MES系统是什么?

    ERP是什么?MES是什么?APS又是什么?无论他们有什么功能,对企业有什么意义,不过都是计算机在读写一些数据而已.实际上这一切的本质不过是数据在硬盘和内存中快速的读和写. ERP是--,APS是-- ...

  10. 探索javascript----浅析js模块化

    引言: 鸭子类型: 面向对象的编程思想里,有一个有趣的概念,叫鸭子类型:“一只鸟走起来像鸭子.游起泳来像鸭子.叫起来也像鸭子,那它就可以被当做鸭子.也就是说,它不关注对象的类型,而是关注对象具有的行为 ...

随机推荐

  1. 教你如何写thinkphp多表查询语句

    1.table()函数 thinkphp中提供了一个table()函数,具体用法参考以下语句: $list=$Demo->table('think_blog blog,think_type ty ...

  2. date 修改系统时间

    # date -s "2017/03/27 12:33:58"

  3. schema中的虚拟属性方法

    schema中的虚拟属性方法相当于vue中的计算属性,它是通过已定义的schema属性的计算\组合\拼接得到的新的值 var personSchema = new Schema({ name: { f ...

  4. nyoj116 士兵杀敌(二)树状数组 插点问线

    士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军经常想知 ...

  5. Python 按当前日期(年、月、日)创建多级目录的方法

    先看实际效果,现在时间2018.4.26 使用python脚本按照年月日生成多级目录,创建的目录可以将系统生成的日志文件放入其中,方便查阅,代码如下: #!/usr/bin/env python #c ...

  6. centos7 ping: www.baidu.com: Name or service not known

    [root@www ~]# ping www.baidu.com ping: www.baidu.com: Name or service not known [root@www ~]# 1.网络配置 ...

  7. 一:cocos2dx 3.2 尚不支持cubeMap?二:光照需要shader实现

    一: cocos2dx 3.2 尚不支持cubeMap? 因为需要调用cocos2dx 封装的bindTexture的方法,发现只能绑定2DTexture,对Cube_Map无能无力.顿感累觉不爱…… ...

  8. spark内存概述

    转自:https://github.com/jacksu/utils4s/blob/master/spark-knowledge/md/spark%E5%86%85%E5%AD%98%E6%A6%82 ...

  9. JAVA-JSP动作元素之include

    相关资料:<21天学通Java Web开发> 结果总结:1.<jsp:xxx /> 或着<jsp:xxx > </jsp:xxx>2.与存取JavaBe ...

  10. activiti5.13工作流系列(一)-初识

    1.什么是工作流? 工作流就是让多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程,工作流由实体(Entity).参与者(Participant).流程定义(Flow Definition) ...