hdu3635之并查集
来源:互联网 发布:房屋在线设计软件 编辑:程序博客网 时间:2024/06/05 10:31
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<cmath>#include<iomanip>#define INF 99999999using namespace std;const int MAX=10000+10;/*father[i]表示i节点的父亲,rank[i]i所在集合的元素sum转换的次数*/int father[MAX],rank[MAX],sum[MAX];void makeset(int num){for(int i=1;i<=num;++i){father[i]=i;rank[i]=1;sum[i]=0;}} int findset(int v){if(v == father[v])return father[v];int temp=findset(father[v]);sum[v]+=sum[father[v]];father[v]=temp;//这里压缩路径是关键,由于压缩路径,节点增加每次增加的转移数量只可能是1return father[v];}void Union(int x,int y){int a=findset(x);int b=findset(y);if(a == b)return;father[a]=b;sum[a]=1;rank[b]+=rank[a];}int main(){int t,n,m,a,b,num=0;char s;cin>>t;while(t--){scanf("%d%d",&n,&m);printf("Case %d:\n",++num);makeset(n);for(int i=0;i<m;++i){getchar();scanf("%c",&s);if(s == 'T'){scanf("%d%d",&a,&b);Union(a,b);}else{scanf("%d",&a);int x=findset(a);printf("%d %d %d\n",x,rank[x],sum[a]);}}}return 0;}
- hdu3635之并查集
- hdu3635(并查集)
- hdu3635并查集
- HDU3635(并查集)
- hdu3635并查集
- hdu3635(并查集)
- HDU3635 Dragon Balls 并查集
- HDU3635 带权并查集
- HDU3635 Dragon Balls(并查集)
- hdu3635 Dragon Balls--并查集
- HDU3635 Dragon Balls(并查集)
- HDU3635:Dragon Balls(并查集)
- Dragon Balls(hdu3635带权并查集)
- 【hdu3635】Dragon Balls —— 并查集
- HDU3635 Dragon Balls 解题报告【带权并查集】
- 带权并查集--hdu3635 Dragon Balls
- 09-07 HDU_Steps5.1 并查集 HDU1829 HDU1325 HDU1598 HDU3461 HDU3635 HDU2473 HDU3172 HDU3038
- 数据结构之并查集
- Lucene全文搜索框架
- ZOJ2599 数位统计论文例题
- 去大公司实习的好处
- C#中的常用类库小结
- 题目1174:查找第K小数
- hdu3635之并查集
- 你真的懂得margin么?
- 公司中 C和C++程序员进阶之路
- hdu 1599 find the mincost route
- 沙尘暴来袭
- The kth great number
- 阿里巴巴电话面试
- 天天都在
- The Frog's Games