hdu 1856 More is better
来源:互联网 发布:平板电脑软件大全 编辑:程序博客网 时间:2024/06/06 02:55
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856
简单的并查集的运用,如下:
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>const int Max_N = 100050;struct UnionFind{int ans, par[Max_N], rank[Max_N], num[Max_N];inline void init(int n){ans = 1;for (int i = 1; i < Max_N; i++){par[i] = i;rank[i] = 0;num[i] = 1;}}inline int find(int x){while (x != par[x]){x = par[x] = par[par[x]];}return x;}inline void unite(int x, int y){x = find(x), y = find(y);if (x == y) return;if (rank[x] < rank[y]){par[x] = y;num[y] += num[x];num[x] = 0;ans = std::max(num[y], x);} else {par[y] = x;num[x] += num[y];num[y] = 0;ans = std::max(num[x], ans);if (rank[x] == rank[y]) rank[x]++;}}}rec;int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);freopen("out.txt", "w+", stdout);#endifint n, a, b;while (~scanf("%d", &n)){rec.init(n);for (int i = 0; i < n; i++){scanf("%d %d", &a, &b);rec.unite(a, b);}printf("%d\n", rec.ans);}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
- 刘强东哈佛演讲
- 游承超:手机钢化玻璃膜平边与弧边的区别(1P)
- keepalived+redis 实现高可用的自动故障转移failover
- Android Handler机制
- poi操作excel初步
- hdu 1856 More is better
- Java 基础 第二天
- 日常笔记
- 查找pop pop ret call dword ptr [esp+nn]指令的方法
- helloworld
- jvm 垃圾收集器
- 04.JDBC编程之指定变量&批处理
- JAVA知识(005)--分支和循环3
- 旅行家的预算