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 bal…
题意: N个城市,每个城市有一个龙珠. 两个操作: 1.T A B:A城市的所有龙珠转移到B城市. 2.Q A:输出第A颗龙珠所在的城市,这个城市里所有的龙珠个数,第A颗龙珠总共到目前为止被转移了多少次. 思路: 前两个好求,第三个求转移的次数只要把它到根的路径上的值加起来就行了 看代码 代码: int N,Q; int fa[10005], ballNum[10005], moveTime[10005]; int findFa(int x){ if(fa[x]==x) return fa[x]…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4384    Accepted Submission(s): 1673 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时间,城市i的所有的龙珠都会被转移到城市j中. 现在有两种操作: 1. T A B,表示将A龙珠所在城市的所有龙珠全部转移到B龙珠所在城市去. 2. Q A,表示询问A龙珠所在的城市X,以及X城市有几个龙珠,A龙珠被转移了几次. 输入: 第一行输入1个整型数字t,表示一共t组测试样例. 接下来,每组样…
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3726    Accepted Submission(s): 1415 Problem Description In 12th Zhejiang College Students Games 2007, there was a new stadium built…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2909    Accepted Submission(s): 1125 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3363    Accepted Submission(s): 1304 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7926    Accepted Submission(s): 2937 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8072    Accepted Submission(s): 2991 Problem Description Five hundred years later, the number of dragon balls will increase unexpect…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3635 题意:有n个龙珠,n个城市.初始状态第i个龙珠在第i个城市里.接下来有两个操作: T A B:把A号龙珠所在的城市的所有龙珠全部转移到B城市中. Q A:查询A龙珠,要求:A龙珠所在城市,该城市龙珠数量,A移动的次数. 思路:用并查集可以轻松解决Q的前两个问题.关键在于如何统计A的移动次数,因为在T的时候是要将A所在城市的所有龙珠都要转移到B,那就要A集合里所有龙珠的移动次数都+1.假如我们在…