ZOJ-2833Friendship(简单并查集)
来源:互联网 发布:mac os x 10.12懒人版 编辑:程序博客网 时间:2024/06/06 12:28
//查找这个人又多少个朋友,必须从他的祖先开始查,num[find(a)];
AC代码:
#include<stdio.h>#define max 100005int p[max];int num[max];char s[max];int a,b;int find(int k){ if(p[k]!=k) { p[k]=find(p[k]); num[k]+=num[p[k]]; } return p[k];}int bing(int x,int y){ int x1=find(x); int y1=find(y); if(x1==y1) { return 0; } p[y1]=x1; num[x1]+=num[y1]; return 1;}int main(){ int m,n; int k=1; int o=0; while(scanf("%d%d",&m,&n)!=EOF&&m) { int i,j; if(o) { printf("\n"); } o=1; for(i=1;i<=max;i++) { p[i]=i; num[i]=1; } printf("Case %d:\n",k++); for(i=0;i<n;i++) { scanf("%s",s); if(s[0]=='M') { scanf("%d%d",&a,&b); bing(a,b); } if(s[0]=='Q') { scanf("%d",&a); printf("%d\n",num[find(a)]); } } } return 0;}
0 0
- ZOJ-2833Friendship(简单并查集)
- zoj 2833 Friendship(并查集)
- zoj 2833 Friendship(并查集)
- ZOJ 2833 Friendship(并查集) 简单题
- ZOJ 2833 Friendship 并查集
- ZOJ 2833-Friendship(并查集+优化)
- zoj Friendship 并查集
- ZOJ2833 Friendship(并查集)
- 并查集(A - Friendship)
- zoj2833 Friendship //并查集
- 并查集——Friendship
- zoj 2833 Friendship
- zoj - 2833 - Friendship
- ZOJ 2833 Friendship
- ZOJ 2833 Friendship
- zoj-2833 friendship
- zoj 2833 friendship
- zoj 2833 Friendship
- 数电模电基础(1)分压电路
- mybatis 参数为String,if test读取该参数
- C#excel、sql sever批量数据的导入导出
- 黑马程序员——Java中的String类总结
- 在firstactivity中加载布局文件
- ZOJ-2833Friendship(简单并查集)
- 关于:Java 类文件的内部情况课程详析
- Myeclispse导出带图片的jar生成exe(1)
- iOS - 序
- iOS7 imageWithContentsOfFile 问题
- OS X 10.10.4更新完成后pdf中无法使用单指按压查找与数据检测功能
- 06-2. 字符串字母大小写转换(10)
- Mac OS环境变量设置
- BZOJ 1008 越狱