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
 

思路:并查集,在查找,路径压缩的时候,用num[i]记录i被移动的次数,有:sum[i] += sum[father[i]]。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int father[], num[], city[];
void init(int n)
{
for(int i = ;i <= n;i ++)
{
father[i] = i;
city[i] = ;
num[i] = ;
}
}
int find(int x)
{
if(x == father[x])
return x;
int temp = find(father[x]);
num[x] += num[father[x]];
father[x] = temp;
return father[x];
}
void Unit(int x, int y)
{
int a = find(x);
int b = find(y);
if(a != b)
{
father[a] = b;
num[a] = ;
city[b] += city[a];
city[a] = ;
}
}
int main(int argc, char const *argv[])
{
int T, N, Q, a, b, cnt = ;;
char str[];
scanf("%d", &T);
while(T--)
{
printf("Case %d:\n", ++cnt);
scanf("%d%d", &N, &Q);
init(N);
for(int i = ;i < Q;i ++)
{
scanf("%s", str);
if(str[] == 'T')
{
scanf("%d%d", &a, &b);
Unit(a, b);
}
else
{
scanf("%d", &a);
int temp = find(a);
printf("%d %d %d\n", temp, city[temp], num[a]);
}
}
}
return ;
}

HUD --- 3635的更多相关文章

  1. 如何用Unity GUI制作HUD

    若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...

  2. xamarin UWP平台下 HUD 自定义弹窗

    在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...

  3. xamarin UWP设置HUD加载功能

    使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...

  4. OSG中的HUD

    OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...

  5. CREATE A ENERGY / HEALTH BAR HUD

    Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...

  6. iOS之UI--指示器HUD的创建和设置

    指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...

  7. NGUI:HUD Text(头顶伤害漂浮文字)

    HUD Text 很早之前就有闻于NGUI中的HUD Text插件,今天得以尝试,看了会儿官方的文档,楞是没给看明白,官方的ReadMe.txt写的使用方法如下: 官网Usage 1. Attach ...

  8. iOS开发必备HUD(透明指示层)

    iOS开发必备HUD(透明指示层) 字数421 阅读2123 评论1 喜欢51 1.MBProgressHUD GitHub地址:https://github.com/jdg/MBProgressHU ...

  9. UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类

    转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...

随机推荐

  1. Linux/Unix下设置定时任务

    Unix系统提供了cron和at命令,使系统和用户可以定时运行一定的程序,而不需手工启动. 使用cron用于周期性的执行一个命令,为了使用它,必须编辑crontab文件.系统缺省的/etc/cront ...

  2. mysql 表操作

    创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...

  3. 《Velocity 模板使用指南》中文版[转]

    转自:http://blog.csdn.net/javafound/archive/2007/05/14/1607931.aspx <Velocity 模板使用指南>中文版 源文见 htt ...

  4. 【原创】CMD常用命令:解决实际问题

    1.查找某一目录下后缀名文某某的所有文件. 命令格式:dir *.mp3 /a -d/b/s >C:\Users\leemo\Desktop\total.txt MP3为文件后缀名.>是命 ...

  5. JavaScript学习总结【7】、JS RegExp

    1.RegExp 简介 RegExp 即正则表达式(Regular Expression,在代码中常简写为 regex.regexp或RE/re/reg),就是使用单个字符串来描述.匹配一系列符合某个 ...

  6. OpenCV例程实现人脸检测

    前段时间看的OpenCV,其实有很多的例子程序,参考代码值得我们学习,对图像特征提取三大法宝:HOG特征,LBP特征,Haar特征有一定了解后. 对本文中的例子程序刚开始没有调通,今晚上调通了,试了试 ...

  7. Hibernate 使用说明

    Eclipse中hibernate连接mySQL数据库练习(采用的是hibernate中XML配置方式连接数据库,以后在更新其他方式的连接) Hibernate就是Java后台数据库持久层的框架,也是 ...

  8. [Linux]Vim的安装及使用

    1.安装:$sudo apt-get install vim 2.查看Vim所在路径$whereis vim 3.启动Vim $'/usr/bin/vim.tiny'  4. 退出Vim窗口:Ctrl ...

  9. Android Activity 管理

  10. MySQL在创建存储过程的时候,语法正确却提示You have an error in your SQL syntax

    我在使用MySQL工具编写MySQL存储过程的时候,明明语法正确,但是却一直提示You have an error in your SQL syntax. 比如下面一段代码 CREATE PROCED ...