并查集——Friendship
来源:互联网 发布:linux系统工程师培训 编辑:程序博客网 时间:2024/06/18 04:46
题目:
代码:
#include<stdio.h>int pre[100005],sh[100005];int find(int x){if(x!=pre[x])pre[x]=find(pre[x]);return pre[x];}int find2(int x){while(x!=pre[x])x=pre[x];return x;} int main(void){char s;int xx,yy;int a,b;int i;int f=0;int n,m;int k=0;int x,y;while(scanf("%d%d",&n,&m)!=EOF){for(i=0;i<100005;i++){pre[i]=i;sh[i]=1;}k++;if(f){printf("\n");f=1;}printf("Case %d:\n",k);f=1;for(i=0;i<m;i++){getchar();scanf("%c",&s);if(s=='M'){scanf("%d%d",&xx,&yy);a=xx;b=yy;a=find(a);b=find(b);if(a!=b){pre[b]=pre[a];sh[a]=sh[a]+sh[b];}}else{if(s=='Q'){scanf("%d",&xx);x=xx;y=find2(x);printf("%d\n",sh[y]);} }}} return 0;}
0 0
- 并查集——Friendship
- zoj2833 Friendship //并查集
- zoj Friendship 并查集
- zoj 2833 Friendship(并查集)
- ZOJ2833 Friendship(并查集)
- 并查集(A - Friendship)
- ZOJ 2833 Friendship 并查集
- zoj 2833 Friendship(并查集)
- ZOJ 2833 Friendship(并查集) 简单题
- ZOJ 2833-Friendship(并查集+优化)
- ZOJ-2833Friendship(简单并查集)
- Codeforces 771A Bear and Friendship Condition[并查集]
- CodeForces 791B Bear and Friendship Condition【并查集】
- Codeforces Round #405 Bear and Friendship Condition 并查集
- Codeforces #406 (Div. 2) B. Bear and Friendship Condition(并查集
- hdu1198—并查集
- 并查集—入门
- 并查集—应用
- Ubuntu 12.04以上 安装搜狗输入法
- 交换两个变量的多种方法
- 八皇后问题
- pat:1002(Advanced)
- 常见音频格式
- 并查集——Friendship
- 1028 List Sorting (25)(友元函数的使用)
- 【BZOJ 1975】 魔法猪学院
- 从阅读中寻找乐趣,在学习中不断成长
- hdu-1856 More is better
- mysql之查询优化探索
- cocos2dx 文件处理
- [UIImage imageNamed:@""]使用误区
- C++一些注意点之new和malloc