hdu1856 查并集
来源:互联网 发布:韦德09年数据 编辑:程序博客网 时间:2024/05/21 14:44
对特殊情况总是考虑不周~~~当n=0应输出1;
http://acm.hdu.edu.cn/showproblem.php?pid=1856
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int p[10000005];int vis[10000005];int maxx;inline void make_set(int n){ p[n]=n;}int find_set(int i){ int j=i; while(j!=p[j]) { j=p[j]; } return p[i]=j;}int Union(int a,int b){ a=find_set(a); b=find_set(b); if(a==b) { //vis[a]++; //if(vis[a]>maxx) // maxx=vis[a]; return 0; } else { p[a]=b; vis[b]+=vis[a]; if(vis[b]>maxx) maxx=vis[b]; return 1; }}int main(){ int n; while(scanf("%d",&n)!=EOF) { int i; maxx=0; if(n==0) { printf("1\n"); continue; } memset(vis,0,sizeof(vis)); memset(p,0,sizeof(p)); for(i=0;i<n;i++) { int a,b; scanf("%d%d",&a,&b); if(!vis[a]) { vis[a]=1; make_set(a); } if(!vis[b]) { vis[b]=1; make_set(b); } Union(a,b); } printf("%d\n",maxx); } return 0;}
- hdu1856 查并集
- hdu1856(并查集)
- hdu1856(基础并查集)
- More is better hdu1856 并查集
- hdu1856 ,More is better,并查集
- hdu1856(并查集的简单应用)
- Hdu1856 - More is better - 并查集
- HDU1856 More is better 并查集
- HDU1856 More is better 并查集
- hdu1856 More is better 并查集
- 再水一道并查集,hdu1856
- HDU1856 More is better(并查集)
- hdu1856 More is better 并查集
- 并查集模板题-HDU1856
- hdu1856 More is better--并查集
- hdu1856 More is better 并查集
- hdu1856&&poj1308(基础并查集)
- HDU1856(More is better)—并查集+树
- java获取对象属性类型、属性名称、属性值 .
- 二进制,八进制,十进制,十六进制互相转化的C语言源代码
- 标签入门
- Path expected for join!的解决办法
- struts2导入excel
- hdu1856 查并集
- SPAN和DIV Class与ID的区别汇总
- android Poast方式获取数据网络不稳定
- struts2 标签的使用之 s:iterator
- 各种字符串Hash函数比较
- 好文分享--Linux的概念与体系
- MATLAB 函数句柄Function handle的用法(Af = @(x) A*x;)
- Qt界面中文显示乱码问题
- Android——使用HTTP协议下载文件