博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 1856 - More is better <并查集>
阅读量:4538 次
发布时间:2019-06-08

本文共 896 字,大约阅读时间需要 2 分钟。

//本题用cin超时啊,要用scanf
#define  _CRT_SECURE_NO_WARNINGS#include 
#include
#include
#include
#include
#include
using namespace std;const int maxn = 10000001;int pre[maxn];int topcnt[maxn];int Find(int x){ int l = x; while (l != pre[l]) l = pre[l]; while (l != pre[x]){ int t = pre[x]; pre[x] = l; x = t; } return l;}void join(const int x, const int y){ int fx = Find(x); int fy = Find(y); pre[fx] = fy;}int main(){ int n; while (~scanf("%d", &n)){ if (n == 0){ printf("1\n"); continue; } for (int i = 0; i < maxn; i++) pre[i] = i; memset(topcnt, 0, sizeof(topcnt)); while (n--){ int x, y; scanf("%d %d", &x, &y); join(x, y); } for (int i = 1; i < maxn; i++) topcnt[Find(i)]++; printf("%d\n", *max_element(topcnt + 1, topcnt + maxn)); } return 0;}

转载于:https://www.cnblogs.com/kunsoft/p/5312742.html

你可能感兴趣的文章
Visual Studio提示“无法启动IIS Express Web服务器”的解决方法
查看>>
Java 时间总结
查看>>
jQuery EasyUI 拖放 – 基本的拖动和放置
查看>>
这些年正Android - 母亲
查看>>
[工具] BurpSuite--XssValidator插件
查看>>
LPC1788系统时钟初始化
查看>>
channel vs mutex
查看>>
页面布局(--FlowLayout,--BorderLayout,--GridLayout)
查看>>
实验吧--web--你真的会php吗
查看>>
vue组件化学习第二天
查看>>
网络枚举工具推荐
查看>>
003LeetCode--LongestSubstring
查看>>
quarzt(官方)---给自己看的文档(SchedulerListeners)-8
查看>>
Linux-慕课网学习笔记-3-1命令格式
查看>>
AJAX入门介绍
查看>>
[算法竞赛入门]第一章_算法概述
查看>>
SQL反模式笔记3——主键规范
查看>>
简单粗暴,微生物生态研究中常用数据库简介--转载
查看>>
Oracle -操作数据库
查看>>
c - 给分数分级别
查看>>