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 ...
随机推荐
- Pro Flight YOKE 设备键位映射踩过的坑
背景 VR游戏项目.街机游戏项目7月阶段版本快要结束了,考虑到带有键鼠外设显得逼格比较Low,所以决定采用"高大上"的专业设备来进行游戏操作. 需求 需要将键盘鼠标操作的18个键位 ...
- Count Color 线段树
Count Color Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- Fitnesse - Slim Tables
Fitnesse - Slim Tables 2017-09-28 目录1 什么是Wiki Word?2 Query Table 2.1 Query Table的格式 2.2 源代码3 Scri ...
- Python自学笔记-字符串编码(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 1.理解变 ...
- java 虚拟机与并发处理几个问题简要(二)
六.两个重要的概念性问题: 1.同步:要保持数据的一致性,就需要一种保证并发进程正确执行顺序的机制.这种机制就是 进程同步(Process Synchronization). 竞争资源的多个进程按着特 ...
- HDU1201 水题
做多了年月日,现在基本就能水过了 18岁生日 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- 使用dropload.js插件进行下拉刷新
移动端的下拉刷新是一个比较常见的功能了,网上也有很多框架,插件都有这种功能,所以直接拿来用就好了. html代码: <!--选项卡--><div class="tab&qu ...
- c# 【MVC】WebApi设置返回Json
public static HttpResponseMessage toJson(Object obj) { String str; if (obj is String || obj is Char) ...
- Jquery几行代码解决跟随屏幕滚动DIV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- linux_base_commond_one
1.cd commond a. cd usr 切换到该目录下usr目录 b. cd ../ 切换到上一层目录 c.cd / 切换到系统根目录 d. cd ~ 切换到用户主目录 e. cd - 切 ...