hdoj3635_Dragon Balls
来源:互联网 发布:神魔诛天变身进阶数据 编辑:程序博客网 时间:2024/06/18 15:00
Dragon Balls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2437 Accepted Submission(s): 944
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.
![](http://acm.hdu.edu.cn/data/images/C308_1004_1.jpg)
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.
![](http://acm.hdu.edu.cn/data/images/C308_1004_1.jpg)
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)
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
23 3T 1 2T 3 2Q 23 4T 1 2Q 1T 1 3Q 1
Sample Output
Case 1:2 3 0Case 2:2 2 13 3 2
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int father[10010];int number[10010], mv[10010];void init(){for (int i = 1; i < 10010; i++){father[i] = i;number[i] = 1;mv[i] = 0;}}int find(int x){if (x == father[x]){return x;}else {int fa = father[x];father[x] = find(father[x]);mv[x] += mv[fa];//路径压缩时更新移动的次数return father[x];}}int main(){int t;scanf("%d", &t);int i = 1;while (t--){init();int n, m;scanf("%d%d", &n, &m);getchar();printf("Case %d:\n", i++);while (m--){char str[10];int a ,b;scanf("%s", str);if (str[0] == 'T'){scanf("%d%d", &a ,&b);int xa = find(a);int xb = find(b);mv[xa]++;//根节点总是第一次移动number[xb] += number[xa];number[xa] = 0;father[xa] = xb;}else {scanf("%d", &a);int xa = find(a);printf("%d %d %d\n", xa, number[xa], mv[a]);}}}return 0;}
0 0
- hdoj3635_Dragon Balls
- Labeling Balls
- Dragon Balls
- Dragon Balls
- Balls Rearrangement
- Dragon Balls
- Weight Balls
- Balls Rearrangement
- Dragon Balls
- Dropping Balls
- hdu3635Dragon Balls
- Dropping Balls
- Labeling Balls
- Dragon Balls
- Labeling Balls
- Pingpang Balls
- Dropping Balls
- magic balls
- VS2010中的C++0x特性 以后有时间在看
- 用博客见证自己的成长(perfect)
- VM ware 与主机共享
- java中的动态代理
- Ubuntu 12.10截图快捷键
- hdoj3635_Dragon Balls
- hdu 1217 Arbitrage
- android判断网络是否连接
- 角谷定理:正整数,偶数除以2,基数乘以3加1,问:10000中最长的角谷数
- 关于platform_driver 是如何匹配 platform_device的和如何调用到platform_driver中的probe函数的研究
- servlet中service doGet doPost 的关系
- QT下QTableView显示乱码
- java-jsoup解析html页面的内容
- 我的博客~~