并查集 hdu 1856 示例
来源:互联网 发布:2015广告主投放数据 编辑:程序博客网 时间:2024/05/22 03:37
#include <iostream>#include <string>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <vector>#include <stack>#include <deque>#include <queue>#include <bitset>#include <list>#include <map>#include <set>#include <iterator>#include <algorithm>#include <functional>#include <utility>#include <sstream>#include <climits>#include <cassert>#define BUG puts("here!!!");using namespace std;const int N = 100005;struct Node { int par; int sum;};int SUM;Node p[2*N + 5];void makeSet(int n) { for(int i = 0; i <= 2*n; i++) { p[i].par = i; p[i].sum = 1; } SUM = 1;}int find(int a) { if(a == p[a].par) return a; return p[a].par = find(p[a].par);}void union1(int a, int b) { int fa = find(a); int fb = find(b); if(fa != fb) { p[fa].par = fb; p[fb].sum += p[fa].sum; } if(p[fb].sum > SUM) { SUM = p[fb].sum; }}int main() { int n, a, b; while(scanf("%d", &n) == 1) { makeSet(n); while(n--) { scanf("%d%d", &a, &b); union1(a, b); } printf("%d\n", SUM); } return 0;}Sample Input
4
1 2
3 4
5 6
1 6
4
1 2
3 4
5 6
7 8
Sample Output
4
2
- 并查集 hdu 1856 示例
- 并查集 hdu 1856 示例
- HDU 1856 并查集
- hdu 1856(并查集)
- hdu 1856 并查集
- HDU-1856,并查集
- HDU 1856 并查集
- hdu 1856 并查集
- HDU 1856 并查集
- 并查集 HDU 1856
- hdu 1856并查集
- HDU 1856 并查集
- hdu 1856(并查集)
- hdu 1232 .hdu 1856 并查集 。。。
- 并查集示例1
- HDU 1856(并查集)
- HDU 1856 并查集+离散化
- HDU 1856 简单并查集
- excel的读写操作
- KMP / hdu 1711 [找到匹配的位置并返回]
- log4j和web.xml配置webAppRootKey 的问题
- 致自己
- 关于.cpp和.h文件的区别
- 并查集 hdu 1856 示例
- 堆栈实现的迷宫寻路
- 并查集 示例 : poj 1703 [Find them, Catch them - 帮派之争]
- 共享锁与排它锁
- webdriver实现原理
- 动态调用dll问题
- spring配置可以选择的事务管理器
- Trie 字典树 poj 2001 示例
- 死锁问题分析及解决办法