博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3635 Dragon Balls
阅读量:7011 次
发布时间:2019-06-27

本文共 1127 字,大约阅读时间需要 3 分钟。

难点在于用并查集求与根节点的距离并更新吧。。 遇到过好几次了

 

#include
#include
#include
#include
#include
using namespace std;int n, q, fa[10005], num[10005], cou[10005];void init(){ int i; for(i=1; i<=n; i++) fa[i]=i, num[i]=1, cou[i]=0;}int find(int x){ if(x==fa[x]) return x; int tmp=fa[x]; fa[x]=find(fa[x]); cou[x]+=cou[tmp]; return fa[x];}int main(){ int i, j, T, a, b, ta, tb, ri; char op[4]; scanf("%d",&T); for(ri=1; ri<=T; ri++) { scanf("%d%d",&n,&q); init(); printf("Case %d:\n",ri); while(q--) { scanf("%s",op); if(op[0]=='T') { scanf("%d%d",&a,&b); int ta=find(a), tb=find(b); fa[ta]=tb; cou[ta]++; num[tb]+=num[ta]; } else { scanf("%d",&a); ta=find(a); printf("%d %d %d\n",ta,num[ta],cou[a]); } } } return 0;}

 

转载于:https://www.cnblogs.com/ink-syk/p/3315150.html

你可能感兴趣的文章
folders.cgi占用系统大量资源
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
request内置对象---参数传递
查看>>
两个变量a,b,不用判断语句,找出两个中比较大的那个变量
查看>>
线程相关资料
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
经典组合 | PTS + ARMS打造性能和应用诊断利器
查看>>
我的友情链接
查看>>
android输入限制
查看>>
一:kubeadm初始化Kubernetes集群
查看>>
wget linux
查看>>
漫谈JVM
查看>>
亚马逊的客服真是好
查看>>
磁盘的挂载与卸载 mount umount
查看>>
linux下mysql的常用命令
查看>>
IOS第一个例子的实现 ——HelloApple
查看>>
Nmap 7.70新增功能——扫描主机所有IP
查看>>