hdu 1856 More is better (并查集)
More is better
Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 12171    Accepted Submission(s): 4481
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.
//234MS 1876K 845 B G++
/* 题意:
给出n对朋友关系,求直接或间接认识的最大的集合 并查集:
这题出的是什么数据..
个人觉得数据不是很好,想我的做法应该MLE才对,加上map来做
应该会更好。不过还是简单题 */
#include<iostream>
using namespace std;
int set[];
inline int find(int x)
{
if(x==set[x]) return x;
return find(set[x]);
}
inline void merge(int a,int b)
{
int x=find(a);
int y=find(b);
if(x>y) set[x]=y;
else set[y]=x;
}
int main(void)
{
int n,a,b;
while(scanf("%d",&n)!=EOF)
{
int m=;
for(int i=;i<;i++) set[i]=i;
for(int i=;i<n;i++){
scanf("%d %d",&a,&b);
merge(a,b);
m=a>m?a:m;
m=b>m?b:m;
//printf("*%d %d\n",M[a],M[b]);
}
int s[]={};
int ans=;
for(int i=;i<=m;i++){
int t=find(i);
s[t]++;
if(s[t]>ans) ans=s[t];
}
printf("%d\n",ans);
}
return ;
}
hdu 1856 More is better (并查集)的更多相关文章
- HDU 1856 More is better (并查集)
		题意: 给你两个数代表这两个人是朋友,朋友的朋友还是朋友~~,问这些人组成的集合里面人最多的是多少... 思路: 属于并查集了,我用的是带路径压缩的,一个集合里面所有元素(除了根节点)的父节点都是根节 ... 
- HDU 1856  More is better(并查集)
		http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ... 
- HDU HDU1558 Segment set(并查集+判断线段相交)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一 ... 
- hdu 1257 小希的迷宫 并查集
		小希的迷宫 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 D ... 
- hdu 3635 Dragon Balls(并查集应用)
		Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ... 
- <hdu - 1272>  小希的迷宫  并查集问题 (注意特殊情况)
		本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 Problem Description: 上次Gardon的迷宫城堡小希玩了很久(见Probl ... 
- HDU 4496 D-City(逆向并查集)
		http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后 ... 
- HDU 3407.Zjnu Stadium 加权并查集
		Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ... 
- HDU 1213 - How Many Tables - [并查集模板题]
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ... 
- HDU 4641 K-string 后缀自动机 并查集
		http://acm.hdu.edu.cn/showproblem.php?pid=4641 https://blog.csdn.net/asdfgh0308/article/details/4096 ... 
随机推荐
- [异常笔记]poi读取Excel异常
			Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException: The sup ... 
- git 上传到码云
			创建分支 在码云里创建好分支 命令行进入项目所在的目录 显示码云上的分支 git pull 选择将要编辑的分支(index-fenzhi) git checkout index-fenzhi 查看分支 ... 
- 【HCNE题型自我考究】
			H3CNE题目归结 制定标准 组织: 802.1X协议起源于标准的无线局域网协议802.11.主要目的是为了解决有线局域网用户的接入认证问题. 426.一个包含有华为等多厂商设备的交换网络,其VL ... 
- 算法竞赛入门经典-1.5.4 Q&A
			这小节考察实践能力,要求在不要查书.不要网上找答案,自己用实验的方法解决以下五个问题: 做这五道题时,好几道都没思路,违反了规则到网上找了一圈,居然没找到答案,于是打算写这篇博客.不知是否有更好的实践 ... 
- Failed to read candidate component class错误分析
			org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component c ... 
- Sql Server 表间对应关系
			<1>.关联映射:一对多/多对一 存在最普遍的映射关系,简单来讲就如球员与球队的关系:一对多:从球队角度来说一个球队拥有多个球员 即为一对多多对一:从球员角度来说多个球员属于一个球队 即为 ... 
- 批处理bat实现创建、复制、删除文件及文件夹
			转自:http://blog.csdn.net/linda1000/article/details/10221285 1 建bat文件自动执行复制,删除命令. 例1:以下是复制cd.dll文件至win ... 
- [Jmeter]jmeter数据库性能测试配置
			学习jmeter过程中,记录一些学习过程中的点点滴滴,用于备忘.本文主要介绍的是如何创建一个简单的测试计划用户测试数据库服务器. 一.添加线程组 二.添加JDBC请求 1.在第一步里面定义并发用户以及 ... 
- java存储位置经典例子
			String a="a";String b="b";String c="ab";String d="ab";String ... 
- ubuntu 14.04安装nginx+php
			转自:http://www.cnblogs.com/helinfeng/p/4219051.html 基于最新的Ubuntu 14.04(2014年9月)搭建nginx.php.mysql环境,以下全 ... 
