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): 24825 Accepted Submission(s): 8911
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.
1 2
3 4
5 6
1 6
4
1 2
3 4
5 6
7 8
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.
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX=;
int f[MAX],v[MAX];
int find(int n)
{
if(n!=f[n])
f[n]=find(f[n]);
return f[n];
} int main()
{ int n;
while(cin>>n)
{
for(int i=;i<MAX;i++)
{f[i]=i;v[i]=;}
int a,b;
int t=;
for(int i=;i<n;i++)
{scanf("%d%d",&a,&b);
a=find(a);
b=find(b);
if(a!=b)
{f[a]=b;v[b]+=v[a];t=max(t,v[b]);}
}
cout<<t<<endl;
}
return;
}
hdu-1856-More is better的更多相关文章
- 简单并查集 -- HDU 1232 UVALA 3644 HDU 1856
并查集模板: #include<iostream> using namespace std; ],x,y; ]; //初始化 x 集合 void init(int n) { ; i< ...
- HDU 1856 More is better(并查集+离散化)
题目地址:HDU 1856 水题.因为标号范围太大,而数据数仅仅有10w,所以要先进行离散化.然后就是裸的并查集了. 代码例如以下: #include <iostream> #includ ...
- HDU(1856),裸的带权并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 题意:朋友圈问题,A和B是朋友,B和C是朋友则A和C也是朋友,依次类推,题目的意思就是求最大的朋 ...
- HDU 1856
http://acm.split.hdu.edu.cn/showproblem.php?pid=1856 对于这道题,主要就是让你求出有最多结点的树的树叶: 我们只要利用并查集的知识吧所输入的数据连接 ...
- 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 1856 并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ...
- hdu 1856 More is better (并查集)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
- HDU 1856 Brave Game(巴什博奕)
十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻. 今天,大家选择 ...
- Hdu 1856(离散化+并查集)More is better
题意:一些人遵循朋友的朋友也是朋友原则,现在找出最大的朋友圈, 因为人的编号比较大,但是输入的数据最多是10w行,所以可得出最多也就20w人,所以可以进行一下离散化处理,这样数据就会毫无压力 //// ...
- More is better(hdu 1856 计算并查集集合中元素个数最多的集合)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
随机推荐
- JAVA环境配置-Eclipse新建项目
首先配置安装jdk和jre 安装如下: 然后配置变量环境:右键我的电脑--属性--高级系统设置--环境变量--系统变量--找到PATH--编辑 将安装配置的jdk的目录和jdk目录下的bin目录放入其 ...
- Atitit 常用比较复杂的图像滤镜 attilax大总结
Atitit 常用比较复杂的图像滤镜 attilax大总结 像素画滤镜 水彩油画滤镜 素描滤镜 梦幻镜 特点是中央集焦,周围景物朦化微带光晕,使人产生如入梦境的感觉.常用于拍摄婚纱.明星照,也用于其它 ...
- 快速入门系列--MySQL
一直说要好好复习一下Mysql都木有时间,终于赶上最近新购买了阿里云,决定使用CentOS去试试.NET Core等相关的开发,于是决定好好的回顾下这部分知识,由于Mysql的数据库引擎是插件式的,对 ...
- Unity内置的shader include files
Unity内置的shader include files:这些文件都以.cninc结尾, HLSLSupport.cginc:自动包含,一些跨平台编译相关的宏和定义. UnityShaderVaria ...
- Aspect Oriented Programming
AOP(Aspect Oriented Programming),面向切面编程(也叫面向方面)是目前软件开发中的一个热点.利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度 ...
- JSP网站开发基础总结《一》
经过JAVASE的学习相信大家对JAVA已经不再陌生,那么JAVA都可以干什么呢?做算法.应用程序.网站开发都可以,从今天开始为大家奉上JAVAEE之JSP动态网站开发基础总结. 既然是动态网站开发, ...
- java中final注意的问题
public class Test{ public static void main(String[] args){ Person p = new Person(); } } /* 4.修饰的变量是一 ...
- C#对称加密(AES加密)每次生成的密文结果不同思路代码分享
思路:使用随机向量,把随机向量放入密文中,每次解密时从密文中截取前16位,其实就是我们之前加密的随机向量. 代码 public static string Encrypt(string plainTe ...
- select查询时,如何把指定的行放置在最前面
可以用case when做一个列,然后根据这个列来排序,下面给出代码 ' end) as 'abc' from table order by abc
- Windows Azure Service Bus (4) Service Bus Queue和Storage Queue的区别
<Windows Azure Platform 系列文章目录> 熟悉笔者文章的读者都了解,Azure提供两种不同方式的Queue消息队列: 1.Azure Storage Queue 具体 ...