时间限制:3 秒

内存限制:100 兆

特殊判题:

提交:1362

解决:640

题目描述:

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 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.

输入:

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.

总感觉这个Mr Wang是个恋童癖有木有==||

 #include <iostream>

 using namespace std;

 struct LNode

 {

    LNode * lchild,*rchild;

    int data;

 };

 int Tree[];

 int sum[];

 int getroot(int x)

 {

     if(Tree[x]==-) return x;

 else return getroot(Tree[x]);

 }

 int main()

 {

        int n;

    while(cin>>n)

    {

      int i;

  for(i=;i<;i++)

  {

     Tree[i]=-;

 sum[i]=;

  }

  for(i=;i<n;i++)

  {

     int a,b;

 cin>>a>>b;

 a=getroot(a);

 b=getroot(b);

 if(a!=b)

 {

    Tree[a]=b;

    sum[b]+=sum[a];

 }

  }

  int temp=;

  for(i=;i<;i++)

  {

    if(sum[i]>temp) temp=sum[i];

  }

  cout<<temp<<endl;

    }

         return ;

 }

题目1444:More is better的更多相关文章

  1. 【九度OJ】题目1444:More is better 解题报告

    [九度OJ]题目1444:More is better 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1444 题目描述: ...

  2. 九度OJ-第5章-图论

    二.并查集 1. 例题 题目1012:畅通工程 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:10519 解决:4794 题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出 ...

  3. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  4. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. ●BZOJ 1444 [Jsoi2009]有趣的游戏

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1444题解.1: 概率dp,矩阵乘法,快速幂. 对所有串建立AC自动机, 那么如果在trie树 ...

  6. BZOJ 1444:[JSOI2009]有趣的游戏

    BZOJ 1444:[JSOI2009]有趣的游戏 题目链接 首先我们建出Trie图,然后高斯消元. 我们设\(f_i\)表示经过第\(i\)个点的期望次数: \[ f_x=\sum i\cdot p ...

  7. 51nod 1444 破坏道路(bfs+枚举)

    1444 破坏道路 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 在某一个国家,那儿有n个城市,他们通过m条双向 ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. Codevs 1444 “破锣摇滚”乐队

    1444 “破锣摇滚”乐队   题目描述 Description 你刚刚继承了流行的“破锣摇滚”乐队录制的尚未发表的N(1 <= N <= 20)首歌的版权.你打算从中精选一些歌曲,发行M ...

随机推荐

  1. html笔记02:html,body { ……}

    html,body { margin:0px; height:100%; } html元素可告知浏览器其自身是一个 HTML 文档.body 元素定义文档的主体.它包含文档的所有内容(比如文本.图像. ...

  2. 给jdk写注释系列之jdk1.6容器(13)-总结篇之Java集合与数据结构

         是的,这篇blogs是一个总结篇,最开始的时候我提到过,对于java容器或集合的学习也可以看做是对数据结构的学习与应用.在前面我们分析了很多的java容器,也接触了好多种常用的数据结构,今天 ...

  3. Oracle启动的整个过程

    1.启动选项 在发出startup命令启动数据库时,oracle将在默认位置$ORACLE_HOME/dbs(UNIX/Linux)中查找初始化参数文件.Oracle将以下面的顺序在其中寻找合适的初始 ...

  4. 【策略】UVa 11389 - The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线.给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r.问如何分配路线才能使加班费最少. 虽然代码看起来 ...

  5. poj 1364 差分约束

    思路:设dis[i]为从0点到第i点的序列总和.那么对于A B gt  k 来讲意思是dis[B+A]-dis[A]>k; 对于A B lt k来讲就是dis[B+A]-dis[A]<k; ...

  6. Lombok(1.14.8) - @NonNull

    @NonNull @NonNull,生成一个非空检查. package com.huey.lombok; import lombok.Getter; import lombok.NonNull; im ...

  7. GPU总结(1)

    目录 1.为什么要引入GPU 2.CUDA环境的搭建--CUDA全称Compute Unified Device Architecture统一计算设备架构,CUDA是以后总将GPU作为数据并行计算设备 ...

  8. 【转】MySQL的安装与配置

    一.MySQL的安装 1.在线安装: 命令:sudo apt-get install mysql-server 在安装的过程中将提示为“root”用户设置密码,输入自己的密码即可,安装按成后已自动配置 ...

  9. windows下redis服务安装

    1.redis简介redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(so ...

  10. C#学习笔记之线程 - 使用线程

    基于事件的异步模式 (EAP -- The Event-Based Asynchronous Pattern) EAP提供了一个简单的办法,通过它的类能够提供多线程能力,而不需显式的开启或管理线程.它 ...