hdu 3635 Dragon Balls (MFSet)】的更多相关文章

Problem - 3635 切切水题,并查集. 记录当前根树的结点个数,记录每个结点相对根结点的转移次数.1y~ 代码如下: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; struct MFS { int fa[N], tm[N], cnt[N]; ; i < N; i++) fa[i] = i,…
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…
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…
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): 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): 5340    Accepted Submission(s): 2014 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座城市,现在有2种操作,第一种操作是将x龙珠所在城市的所有龙珠移至y龙珠所在城市,第二种操作是计算x龙珠所在城市y,y城市龙珠个数,以及x龙珠移动的次数. 思路:num[x]用来维护x城市所包含的龙珠个数,cnt[x]维护x龙珠所移动的次数. #include<iostream> #include<algorithm> #includ…
这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时间,城市i的所有的龙珠都会被转移到城市j中. 现在有两种操作: 1. T A B,表示将A龙珠所在城市的所有龙珠全部转移到B龙珠所在城市去. 2. Q A,表示询问A龙珠所在的城市X,以及X城市有几个龙珠,A龙珠被转移了几次. 输入: 第一行输入1个整型数字t,表示一共t组测试样例. 接下来,每组样…
题意: 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…