hdu 3635 Dragon Balls
来源:互联网 发布:雷洋案 知乎 编辑:程序博客网 时间:2024/06/07 06:25
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;const int N=10000+5;int n,bin[N],tot[N],cnt[N];//tot是转移次数,cnt是龙珠次数int _find(int x){ if(x==bin[x]) return x; else { int t=bin[x]; bin[x]=_find(bin[x]);//路径压缩 tot[x]+=tot[t];//将压缩过程中的转移次数相加 return bin[x]; }}void _union(int x,int y){ int fx=_find(x),fy=_find(y); bin[fx]=fy; cnt[fy]+=cnt[fx]; tot[fx]=1;}void init(){ for(int i=0;i<N;i++) { bin[i]=i; tot[i]=0; cnt[i]=1; }}int main(){ int T,i,q,cas=0,x,y; char cmd[10]; scanf("%d",&T); while(T--) { init(); scanf("%d%d",&n,&q); printf("Case %d:\n",++cas); for(i=0;i<q;i++) { scanf("%s",&cmd); if(cmd[0]=='T') { scanf("%d%d",&x,&y); _union(x,y); } else if(cmd[0]=='Q') { scanf("%d",&x); int t=_find(x); printf("%d %d %d\n",t,cnt[t],tot[x]); } } } return 0;}
0 0
- hdu 3635 Dragon Balls
- HDU-3635 Dragon Balls
- HDU 3635 Dragon Balls
- HDU-3635-Dragon Balls
- hdu 3635 Dragon Balls
- HDU 3635 Dragon Balls
- HDU 3635 Dragon Balls
- HDU 3635 Dragon Balls
- HDU 3635 Dragon Balls
- hdu 3635 Dragon Balls
- hdu 3635 Dragon Balls
- HDU - 3635 Dragon Balls
- HDU 3635 Dragon Balls
- HDU 3635 Dragon Balls
- 3635 HDU Dragon Balls
- hdu 3635 Dragon Balls
- hdu-3635 Dragon Balls
- HDU 3635 Dragon Balls
- Windows创建进程winAPI-CreateProcess
- 鸡啄米vc++2010系列28(列表视图控件List Control 下)
- iOS在自定义视图(常用于自定义cell)中获取导航控制器上面的当前的控制器对象
- bootstrap兼容IE9
- 初探 iOS8 中的 Size Class
- hdu 3635 Dragon Balls
- libtool编译
- 从MYSQL数据库随机取出数据
- Java 计算时间差之年龄问题
- C++ ofstream和ifstream详细用法
- Git版本控制器的主要操作
- C#操作mysql数据库的代码实例
- oracle数据库查询多行数据使用wmsys.wm_concat()合并
- java关键字