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
|
Sample Output
|
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 ...
随机推荐
- GCD之信号量机制二
在前面GCD之信号量机制一中介绍了通过信号量设置并行最大线程数,依此信号量还可以防止多线程访问公有变量时数据有误,下面的代码能说明. 1.下面是不采用信号量修改公有变量的值 1 2 3 4 5 6 7 ...
- PHP中isset和empty的区别(最后总结)
PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...
- 每天学点SpringMVC-异常处理
1. 第一步先写个Hello World 1.1 编写一个抛出异常的目标方法 @RequestMapping("/testException.do") public String ...
- TCP/IP(四)网络层
前言 前面给大家介绍了计算机网络的基本概述,物理层和数据链路层.这一篇给大家介绍面试中经常会被问到的网络层.在介绍之前我们回顾一下之前学习的知识! CP/IP协议栈:物理层.链路层.网络层.传输层.应 ...
- Longest Uncommon Subsequence I
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- AMD、CMD、CommonJs规范
AMD.CMD.CommonJs规范 将js代码分割成不同功能的小块进行模块化的概念是在一些三方规范中流行起来的,比如CommonJS.AMD和CMD.接下来我们看一下这几种规范. 一.模块化规范 C ...
- Java Socket通信以及可能出现的问题解决
Java中基于TCP协议实现网络通信的两个类:客户端的Socket和服务器端的ServerSocket. Socket通信模型如图所示: 不管Socket通信的功能有多复杂,任何socket通信过程的 ...
- JavaScript链式调用
1.什么是链式调用? 这个很容易理解,例如 $('text').setStyle('color', 'red').show(); 一般的函数调用和链式调用的区别:链式调用完方法后,return thi ...
- selenium 调用键盘按键
1.想要调用键盘按键操作需要引入keys包: from selenium.webdriver.common.keys import keys 通过send_keys() 调用按键 send_keys( ...
- scala位压缩与行情转换二进制
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer} import java.nio.charset.Charset import ...