More is better-多多益善
题目描述:
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-多多益善的更多相关文章
- 又一个opengl教程,多多益善
http://ogldev.atspace.co.uk/index.html http://wiki.jikexueyuan.com/project/modern-opengl-tutorial/tu ...
- Web性能优化:图片优化
程序员都是懒孩子,想直接看自动优化的点:传送门 我自己的Blog:http://cabbit.me/web-image-optimization/ HTTP Archieve有个统计,图片内容已经占到 ...
- 程序员装B指南
一.准备工作 "工欲善其事必先利其器." 1.电脑不一定要配置高,但是双屏是必须的,越大越好,能一个横屏一个竖屏更好.一个用来查资料,一个用来写代码.总之要显得信息量很大,效率很高 ...
- ubuntu入门
Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音.了解发音是有意义的,您不是第一个为此困惑的人,当然,也不会是最后一个:) 大多数的美国人读 ubun ...
- html5 canvas简易版捕鱼达人游戏源码
插件描述:html5利用canvas写的一个js版本的捕鱼,有积分统计,鱼可以全方位移动,炮会跟着鼠标移动,第一次打开需要鼠标移出背景图,再移入的时候就可以控制炮的转动,因为是用的mouseover触 ...
- HTML5移动端图片左右切换动画
插件描述:HTML5移动端图片左右切换动画 小海今天要给大家分享一款很不错的图片左右切换焦点图动画,并且支持移动端触摸滑动.功能上,这款HTML5图片播放器支持鼠标滑动.手机端触摸滑动以及自动播放.外 ...
- C# 正则表达式
引用自:http://www.cnblogs.com/stg609/archive/2009/06/03/1492709.html 摘要:正则表达式(Regular Expressions),相信做软 ...
- Alamofire 的使用
最近,AFNetworking 的作者Mattt Thompson提交了一个新的类似于 AFNetworking 的网络 基础库,并且是专门使用最新的 Swift 语言来编写的,名为:Alamofir ...
- 【详解】ERP、APS与MES系统是什么?
ERP是什么?MES是什么?APS又是什么?无论他们有什么功能,对企业有什么意义,不过都是计算机在读写一些数据而已.实际上这一切的本质不过是数据在硬盘和内存中快速的读和写. ERP是--,APS是-- ...
- 探索javascript----浅析js模块化
引言: 鸭子类型: 面向对象的编程思想里,有一个有趣的概念,叫鸭子类型:“一只鸟走起来像鸭子.游起泳来像鸭子.叫起来也像鸭子,那它就可以被当做鸭子.也就是说,它不关注对象的类型,而是关注对象具有的行为 ...
随机推荐
- PHP通过__call实现简单的AOP(主事务后的其他操作)比如前置通知,后置通知
/** * person class */ class Person { /** * person class -> function say */ public static function ...
- 开源的报表系统easyreport的部署
https://github.com/xianrendzw/EasyReport/blob/master/docs/manual/version2_0.md
- AngularJS概述-3D
最近工作需要用到,接触的比较多,在此系统学习一下. angular.js 是新一代web MVC开发框架,对应 模型,视图,控制器.,相比 jquery 模式,这种新玩意竟然不需要开发者直接去操作do ...
- 最简短的openvpn的设置方式
这种方式对于测试能否连接到远程系统,十分的有用.尤其是国内复杂的网络环境下,检测一下,到底是服务器的原因,还是网络因素造成的,这是一个快捷的方式. 需要注意的是:这种方法是用明文连接.所有的加密措施都 ...
- application , application pool., W3wp ,httpapplication, domain
Hosting and Consuming WCF Services https://msdn.microsoft.com/en-us/library/bb332338.aspx http://www ...
- 搭建MAC下vim环境
MAC下的IDE实在是不好用,最终放弃了IDE准备直接用vim来看代码了,那么就需要设置一下vim. 将家目录下面.vim中的vimrc用下面的内容替换: " Set vundle sett ...
- Ubuntu下安装JDK1.7
Ubuntu操作系统下如何手动安装JDK1.7呢?本文是我经历的全过程. Ubuntu版本:12.04 LTS JDK版本:1.7.0_04 安装目录:/usr/local/development/j ...
- ARM GNU常用汇编语言介绍
ARM GNU常用汇编语言介绍 ARM汇编语言源程序语句,一般由指令,伪操作,宏指令和伪指令组成. ARM汇编语言的设计基础是汇编伪指令,汇编伪操作和宏指令. 伪操作,是ARM汇编语言程序里的一些特殊 ...
- mysql 5.7.14 安装配置方法图文教程(转)
http://www.jb51.net/article/90259.htm ******************************** 因笔者个人需要需要在本机安装Mysql,先将安装过程记录如 ...
- 【linux】Shell脚本启动程序
Linux 下后台脚本启动Jar程序 Nohup后台输出运行日志 cd /home/zeze/jar/WeiboPost java -jar WeiboAutoPost.jar ../configur ...