Dragon Balls
Dragon Balls |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 784 Accepted Submission(s): 317 |
Problem Description
Five hundred years later, the number of dragon balls will increase unexpectedly, so it\\\\\\\'s too difficult for Monkey King(WuKong) to gather all of the dragon balls together.
![]() His country has N cities and there are exactly N dragon balls in the world. At first, for the ith dragon ball, the sacred dragon will puts it in the ith city. Through long years, some cities\\\\\\\' dragon ball(s) would be transported to other cities. To save physical strength WuKong plans to take Flying Nimbus Cloud, a magical flying cloud to gather dragon balls. Every time WuKong will collect the information of one dragon ball, he will ask you the information of that ball. You must tell him which city the ball is located and how many dragon balls are there in that city, you also need to tell him how many times the ball has been transported so far. |
Input
The first line of the input is a single positive integer T(0 < T <= 100).
For each case, the first line contains two integers: N and Q (2 < N <= 10000 , 2 < Q <= 10000). Each of the following Q lines contains either a fact or a question as the follow format: T A B : All the dragon balls which are in the same city with A have been transported to the city the Bth ball in. You can assume that the two cities are different. Q A : WuKong want to know X (the id of the city Ath ball is in), Y (the count of balls in Xth city) and Z (the tranporting times of the Ath ball). (1 <= A, B <= N) |
Output
For each test case, output the test case number formated as sample output. Then for each query, output a line with three integers X Y Z saparated by a blank space.
|
Sample Input
2 |
Sample Output
Case 1: |
Author
possessor WC
|
Source
2010 ACM-ICPC Multi-University Training Contest(19)——Host by HDU
|
Recommend
lcy
|
/*
靠,乱搞一发竟然水过 用并查集记录龙珠的根节点(也就是龙珠所在的城市,用一个辅助数组表示城市i对应的龙珠数)
然后查询的时候经过几层节点,就对应转移了几次
*/
#include<bits/stdc++.h>
using namespace std;
int bin[];//键并查集
int val[];//保存每个城市的龙珠数量
int t,n,m;
int x,y;
char op[];
void inti()
{
for(int i=;i<=n;i++)
bin[i]=i,val[i]=;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
scanf("%d",&t);
for(int Case=;Case<=t;Case++)
{
printf("Case %d:\n",Case);
scanf("%d%d",&n,&m);
inti();
for(int i=;i<m;i++)
{
scanf("%s",&op);
if(op[]=='T')//转移
{
scanf("%d%d",&x,&y);
while(x!=bin[x])//找根节点
x=bin[x];
while(y!=bin[y])//找根节点
y=bin[y];
val[y]+=val[x];//转移龙珠
val[x]=;
bin[x]=y;//转移龙珠x的根节点
}
else//查询
{
scanf("%d",&x);
int step=;
while(x!=bin[x])
x=bin[x],step++;
printf("%d %d %d\n",x,val[x],step);
}
}
}
return ;
}
Dragon Balls的更多相关文章
- hdu 3635 Dragon Balls(并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls (带权并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdoj 3635 Dragon Balls【并查集求节点转移次数+节点数+某点根节点】
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
- HDU 3635:Dragon Balls(并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 3635 Dragon Balls(超级经典的带权并查集!!!新手入门)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Dragon Balls[HDU3635]
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- F - Dragon Balls
Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficu ...
随机推荐
- grunt学习笔记1 理论知识
你需要检查js语法错误,然后再去压缩js代码.如果这两步你都去手动操作,会耗费很多成本.Grunt就能让你省去这些手动操作的成本. “—save-dev”的意思是,在当前目录安装grunt的同时,顺便 ...
- .NET 动态脚本语言
Script.NET (S#) 是一种允许为你的应用程序自定义行为,与本地.NET对象.类型和组件交互动态的脚本语言.托管应用程序本身可以改变一个xml配置脚本运行时的默认行为,更换绑定的方法,属性, ...
- Highway Networks
一 .Highway Networks 与 Deep Networks 的关系 深层神经网络相比于浅层神经网络具有更好的效果,在很多方面都已经取得了很好的效果,特别是在图像处理方面已经取得了很大的突破 ...
- BGP协议
BGP属于自治系统间路由协议.BGP的主要目标是为处于不同AS中的路由器之间进行路由信息通信提供保障.BGP既不是纯粹的矢量距离协议,也不是纯粹的链路状态协议,通常被称为通路向量路由协议.这是因为BG ...
- Mysql连接报错:1130-host ... is not allowed to connect to this MySql server如何处理
这个问题是因为在数据库服务器中的mysql数据库中的user的表中没有权限(也可以说没有用户),下面将记录我遇到问题的过程及解决的方法. 在搭建完LNMP环境后用Navicate连接出错 遇到这个问题 ...
- [SDOI2009]晨跑
又是一道山东省选的题目,居然题目又十分水100行的代码就随随便便AC了. Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止 ...
- JAVA编码互转(application/x-www-form-urlencoded)
本质上来说,java.net.UrlEncoder适用于将 String 转换为 application/x-www-form-urlencoded MIME 格式的静态方法 时 ,使用 但!一般情况 ...
- Python自学笔记-递归函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 递归函数 ...
- M-移动端的webapp页面布局教程和webapp实战分析
http://www.25xt.com/html5css3/8092.html 响应式设计 1 媒体查询 适用于不同固定宽度设计 媒体类型 : screen 屏幕 print 打印机 handheld ...
- Oracle虚拟机VirtualBox安装成功后的注意事项
首先VirtualBox的安装教程 (1)按文档安装 (2)安装完之后配置共享文件夹 (3)安装windowxp镜像 (4)安装Oracle 详情请见Oracle安装文档 (5)启动xp虚拟机 (6 ...