HDU 1856 More is better 并查集
来源:互联网 发布:北京师范学校网络教育 编辑:程序博客网 时间:2024/05/06 06:48
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1856
给你n个关系
求最大连通图的节点个数
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;const int N=10000001;typedef long long LL;int parent[N],xh[N];int n;void UFset(){ for(int i=0;i<N;i++) { parent[i]=i; xh[i]=1; }}int find(int x){ int r=x; while(r!=parent[r]) r=parent[r]; while(parent[x]!=r) { parent[x]=r; x=parent[x]; } return r;}void insert(int x,int y){ x=find(x); y=find(y); if(x==y) return ; xh[x]+=xh[y];//这个地方要和下面的对应 parent[y]=x;}int main(){ int i,j,a,b; while(cin>>n) { UFset(); int m=0; while(n--) { scanf("%d%d",&a,&b); m=max(m,a); m=max(m,b); insert(a,b); } int t=0; for(i=0;i<=m;i++) if(t<xh[i]) t=xh[i]; printf("%d\n",t); } return 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
- 关于camera CTS调试中遇到的问题
- 怎么用u盘安装CentOS 6.4?
- 几个容易混淆的逻辑运算
- iptables下state的4种形式
- C#计算一个月的具体工作天数
- HDU 1856 More is better 并查集
- Windows下创建只有扩展名(.pypirc)的文件
- 关于除法运算的比较
- 如何实现页面静态化:
- vb.net CPU & RAM 显示程序
- DirectX 3D_实践之在DirectX3D中实现摄像机方位的动态变换
- CentOS下安装Oracle 10g--上
- 两种常见排序算法
- CRM2011资源管理器