|
||||||||||
Magic treeTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 298 Accepted Submission(s): 90 Problem Description Sailormoon girls have a beautiful garden, though there is only a tree in it. The tree is quite magic that it will grow different fruits to fit gilrs' demands (xq likes bananas best, wj prefers to kiwi fruits and lff loves tomatoes). Besides these, the tree has N forks which are connected by branches, girls mark the forks by 1 to N and the root is always marked by 1. Fruits will grow on the forks and every fork will grow several fruits. But the tree is too strange that it has many branches(even between two nodes may have more than one branch). In order to pick fruits more convenient and watch more clearly, Sailormoon girls want to cut extra branches by using minimum cost, after that, they also want to know how many fruits are there in a sub-tree. The trouble is that the tree will grow new fruits and girls will pick up some ones from the tree. Can you help them? Input Input contains multiple cases. Each case contains several lines. The first line contains two integers N, M(N<=100,000, M<=151,000), representing the number of forks and the number of branches in the tree. The following M lines each has three integers u, v and c, which means fork u and fork v are connected by a branch, if you want to cut it, you have to cost c (arbitrary two c will be different, c<=200,000). The next line contains an integer P, representing the operations following. "G x y" which means the fork x will grow y more fruits ; "C x" which means girls will pick all fruits on the fork x; "Q x" which means girls want to know the number of fruits in the sub-tree above the fork x, including the fruits (if exists) on the fork x. Note the tree is empty at the beginning, every number will not exceed the range of integer. Output For every "Q x", output the answer per line. Sample Input
Sample Output
Author wangjing1111 Source | ||||||||||
|