题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856

题意:王老师要找一些男生帮助他完成一项工程。要求最后挑选出的男生之间都是朋友关系,可以说直接的,也可以是间接地。问最多可以挑选出几个男生(最少挑一个)。
         这是一个有关并查集的题目。只不过不是求有几个集合,而是求每个集合中元素的个数,进而求出个数的最大值。和求集合个数的方法差不多,只需要在合并两个集合时处理一下,让这两个集合的元素个数也合并一下就行了。接下来只需要找出最大值即可。要注意的一个地方就是:当n=0时,要输出1。
 
各种坑......
 
代码:
 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <iomanip>
#include <queue>
#include <stdlib.h>
using namespace std; int f[],num[];
int n,m; void init()
{
for(int i=;i<=;i++){
f[i]=i;
num[i]=;
}
} int find(int x)
{
if(x!=f[x])
f[x]=find(f[x]);
return f[x];
} void Union(int x,int y)
{
int p=find(x);
int q=find(y);
if(p != q){
f[p] = q;
num[q]+=num[p];
}
} int main()
{
int n,m,i,j,a,b;
while(~scanf("%d",&n)){
if(n==){
printf("1\n");
continue;
}
init();
int max=;
for(i=;i<n;i++){
scanf("%d%d",&a,&b);
Union(a,b);
}
for(j=;j<=;j++){
if(num[j]>max)
max=num[j];
}
printf("%d\n",max);
}
}

hdu More is better的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

  10. HDU 2586

    http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...

随机推荐

  1. c#操作appsettiongs

    try { //指定要修改的配置文件的路径 Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWe ...

  2. 位图像素的颜色 携程编程大赛hdu

    位图像素的颜色 Time Limit: 2000/1000 MS (Java/Others)    MemoryLimit: 32768/32768 K (Java/Others) Total Sub ...

  3. Android 自己定义ScrollView ListView 体验各种纵向滑动的需求

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38950509.本文出自[张鸿洋的博客] 1.概述 群里的一个哥们有个需求是这种: ...

  4. JS学习笔记-OO疑问之封装

    封装是面向对象的基础,今天所要学习的匿名函数与闭包就是为了实现JS的面向对象封装.封装实现.封装变量,提高数据.系统安全性,封装正是面向对象的基础. 一.匿名函数 即没有名字的函数,其创建方式为 fu ...

  5. JAVA开源爬虫,WebCollector,使用方便,有接口。

    假设你想下载整个网站内容爬行动物,我不希望配置heritrix复杂的爬行动物,要选择WebCollector.项目github一个不断更新. github源地址:https://github.com/ ...

  6. 九度OJ 1177 查找 (模拟)

    题目1177:查找 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5659 解决:1667 题目描写叙述: 读入一组字符串(待操作的),再读入一个int n记录记下来有几条命令,总共同拥有 ...

  7. 计算机管理系统——VB与Excel联系

    今天爆震室管理系统--学生查看机器状态的时候发现有一个"导出到excel"的button.我去.感情还得跟excel表链接. 于是我咬碎了一地小银牙.一个下午都在查询vb与exce ...

  8. 【YouVersion】 The Bible 圣经App

    [YouVersion] The Bible 圣经 App 今天向大家郑重推荐一款非常棒的圣经App : <The Bible>   YouVersion 团队开发的全球下载量和安装数目第 ...

  9. URAL - 1966 - Cycling Roads(并检查集合 + 判刑线相交)

    意甲冠军:n 积分,m 边缘(1 ≤ m < n ≤ 200),问:是否所有的点连接(两个边相交.该 4 点连接). 主题链接:http://acm.timus.ru/problem.aspx? ...

  10. Lua 环境结构 --Linux

    curl -R -O http://www.lua.org/ftp/lua-5.2.3.tar.gz tar zxf lua-5.2.3.tar.gz cd lua-5.2.3 make linux ...