hdu 1856 More is better(数据结构:并查集)
来源:互联网 发布:unity3d游戏开发流程 编辑:程序博客网 时间:2024/06/18 02:59
Memory Limit: 327680/102400 K (Java/Others)
注意题头标明的内存...
看到别人开10,000,000大的数组直接吓尿了
看到评论里面的人说数据太水100,000的数组就够了
不知道这个坑爹的题目把数据搞那么大干什么
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAXN 100100using namespace std;int cnt[MAXN];int p[MAXN];int find(int x) { return p[x] == -1 ? x : p[x] = find(p[x]);}int main(void) { int n, i, a, b, max_ans; while(cin >> n) { memset(p, -1, sizeof(p)); for(i=1; i<=MAXN; ++i) cnt[i] = 1; while(n--) { cin >> a >> b; a = find(a); b = find(b); if(a != b) { p[b] = a; cnt[a] += cnt[b]; } } max_ans = 0; for(i=1; i<=MAXN; ++i) { if(p[i] == -1) max_ans = max(max_ans, cnt[i]); } cout << max_ans << endl; } return 0;}
0 0
- HDU 1856 More is better (数据结构,并查集)
- hdu 1856 More is better(数据结构:并查集)
- hdu 1856 More is better(并查集基础)
- hdu 1856 More is better 并查集(二)
- 并查集 Hdu 1856 More is better
- hdu 1856 More is better (并查集入门)
- HDU 1856 More is better 并查集 路径压缩
- hdu 1856 More is better(并查集)
- hdu 1856 More is better(并查集)
- hdu 1856 more is better 并查集
- hdu 1856 More is better 并查集
- HDU 1856 More is better 并查集
- hdu 1856 More is better(并查集)
- hdu 1856 More is better (并查集)
- HDU 1856 More is better 并查集
- HDU-1856-More is better(并查集)
- hdu 1856 More is better --- 并查集
- 【并查集】 hdu 1856 More is better
- 【SDnoip2014夏令营】【day1】
- PKU2349Prime低空飘过
- ubi根文件系统制作文档
- 一个Sqrt函数引发的血案
- 有关next_permutation()函数的用法, poj 2718
- hdu 1856 More is better(数据结构:并查集)
- IO File学习
- 标准C++中的string类的用法总结
- com引用计数
- LeetCode OJ算法题(十四):Longest Common Prefix
- mysql最基本也是最常用的几个命令
- 强大的R
- was cached in the local repository, resolution will not be reattempted until the update interval of
- 大神求解