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
3 3
T 1 2
T 3 2
Q 2
3 4
T 1 2
Q 1
T 1 3
Q 1
 
Sample Output
Case 1:
2 3 0
Case 2:
2 2 1
3 3 2
 
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的更多相关文章

  1. hdu 3635 Dragon Balls(并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. hdu 3635 Dragon Balls (带权并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. hdu 3635 Dragon Balls

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  4. hdoj 3635 Dragon Balls【并查集求节点转移次数+节点数+某点根节点】

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  5. hdu 3635 Dragon Balls(并查集应用)

    Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...

  6. HDU 3635:Dragon Balls(并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  7. HDU 3635 Dragon Balls(超级经典的带权并查集!!!新手入门)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. Dragon Balls[HDU3635]

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. F - Dragon Balls

    Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficu ...

随机推荐

  1. JS中关于数组的内容

      前  言 LIUWE 在网站制作过程中,数组可以说是起着举足轻重的地位.今天就给大家介绍一下数组的一些相关内容.例如:如何声明一个数组和在网站制作过程中我们常用的一些数组的方法.介绍的不好还请多多 ...

  2. Spring定时器的使用详解

    写个最简单的demo吧,反正睡前没什么事儿,来祸害一下园子~~虽然我菜,但是我不会承认啊,哈哈哈 明天详细补充点儿吧,很晚了,不睡觉的程序员不是好程序员,我总能给自己找借口~~~ //spring开启 ...

  3. Java数据库 高级查询

    插入数据记录 1.插入单行数据 语法: INSERT INTO 表名 [(字段名列表)]  VALUES (值列表); 2.插入多行数据 语法:INSERT INTO 新表 (字段名列表) VALUE ...

  4. org.springframework.core.io包内的源码分析

    前些日子看<深入理解javaweb开发>时,看到第一章java的io流,发觉自己对io流真的不是很熟悉.然后看了下JDK1.7中io包的一点点代码,又看了org.springframewo ...

  5. linux free命令解读

    $ free -m total used free shared buffers cached Mem: 1002 769 232 0 62 421 -/+ buffers/cache: 286 71 ...

  6. SLB vs CLB

    什么是SLB? SLB, 服务器负载均衡(Server Load Balancing),可以看作HSRP(热备份路由器协议)的扩展,实现多个服务器之间的负载均衡. 虚拟服务器代表的是多个真实服务器的群 ...

  7. Springmvc学习笔记(一)

    一.sprinvmvc的介绍 1.1.Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 Web 应用程序的全 ...

  8. 基于Quartz实现简单的定时发送邮件

    一.什么是Quartz Quartz 是一个轻量级任务调度框架,只需要做些简单的配置就可以使用:它可以支持持久化的任务存储,即使是任务中断或服务重启后,仍可以继续运行.Quartz既可以做为独立的应用 ...

  9. idea自我使用简单使用方式和出现的一些简单问题以及常用快捷键

    首先配置完Idea的简单使用步骤后,今天在使用Idea时,一直持续提示web项目404的错误提示,因为之前使用idea时,部署的是springBoot的项目,使用的是SpringBoot自带的Tomc ...

  10. html5获取用户当前的地理位置,即经纬度。

    $("document").ready(function(){ getMap(); }); function getMap(){ // 百度地图API功能 var map = ne ...