hdu1856 More is better 基础并查集
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std; #define MAXN 100005
int fa[MAXN]; //父节点
int vis[MAXN];
int Min = 0xffffff;
int Max = ; void init()
{
for (int i = ; i < MAXN; i++)
{
fa[i] = i;
}
} int find(int x)
{
if (x == fa[x])
return x;
else
return fa[x] = find(fa[x]);
} void set_union(int a, int b)
{
int a1 = find(a);
int b1 = find(b); if (a1 == b1)
return;
else
{
if (a1 < b1)
fa[b1] = a1;
else
fa[a1] = b1;
}
} int main()
{
int n;
while (~scanf("%d",&n))
{
init();
for (int i = ; i < n; i++)
{
int a, b;
scanf("%d %d", &a, &b); Min = min(Min, min(a, b));
Max = max(Max, max(a, b)); set_union(a, b);
} int ans = ;
memset(vis, , sizeof(vis));
for (int i = Min; i <= Max; i++)
{
vis[find(i)]++;
if (ans < vis[find(i)])
ans = vis[find(i)];
}
printf("%d\n", ans);
}
//system("pause");
return ;
}
hdu1856 More is better 基础并查集的更多相关文章
- hdu 1829 基础并查集,查同性恋
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- HDU4496 D-City【基础并查集】
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to ...
- AOJ 2170 Marked Ancestor (基础并查集)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=45522 给定一棵树的n个节点,每个节点标号在1到n之间,1是树的根节点,有如 ...
- poj2236 基础并查集
题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...
- 基础并查集poj2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- hdu-1856 More is better---带权并查集
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1856 题目大意: 一个并查集 计算每个集合的元素 找出元素最多的那个集合,输出元素的个数 解题思路: ...
- hdu1325 Is It A Tree? 基础并查集
#include <stdio.h> #include <string.h> ], g[]; int find(int x) //并查集的查找,找到共同的父亲 { if (f[ ...
随机推荐
- Java 兔子问题(斐波那契数列)扩展篇
Java兔子问题(斐波那契数列)扩展篇 斐波那契数列指的是这样一个数列 0, 1, 1, 2,3, 5, 8, 13, 21, 34, 55, 89, 144, ...对于这个数列仅仅能说将兔子生产周 ...
- boost::serialization 用基类指针转存派生类(错误多多,一波三折)
boost::serialization 也支持c++的多态,这样我们就能够通过使用基类的指针来转存派生类, 我们接着上一篇( boost::serialization(2)序列化基类 )的样例来看: ...
- Page Design for Sexable Forum
Design Demo 1. Home of Sexable Forum 1.1 home page not logined. 1,2 home page logined. 2. Pages wit ...
- Ubuntu 16.04 LTS 配置 Jupyter notebook 为服务器
原材料: Ubuntu 16.04 LTS 64bit 已经配置好 IPython 和 Jupyter (安装步骤可以参照:http://www.cnblogs.com/McKean/p/619497 ...
- Arduino 网络时钟client
升级! 添加了12h/24h 的开关,还有标准/ 夏令时开关!见步骤7 & 步骤8. 你是否曾想要一个和办公室时间来源全然准确的表? 这就有一个网络的办公时间server,你能够根据它并同步你 ...
- effctive C++ 读书笔记 条款 16
条款16 成对使用new和delete时要採取同样形式 #include <iostream> #include <string> using namespace std; / ...
- SequenceFileInputFormat区别TextInputFormat
通过InputFormat,Hadoop可以: l 检查MapReduce输入数据的正确性: l 将输入数据切分为逻辑块InputSplit,这些块会分配给Ma ...
- 新装Linux系统没有网卡驱动的解决办法和步骤
Linux下查看网卡驱动和版本信息 - CSDN博客 https://blog.csdn.net/guyan1101/article/details/72770424/ 检查网卡是否加载 - Linu ...
- 增加实时性的异常url检测
技能点: 搭建服务器.restfulapi 在py脚本中调取另一个脚本执行
- iOS 视图在不同View之间的切换(对于convertRect:函数的一些理解)
可以通过以下函数完成坐标体系在不同View之间的切换,如下面是完成当前View向ParentView坐标的转换(一个矩阵转换)CGRect parentRect = [currentView conv ...