F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Magic tree

Time 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
3 2 1 2 4 1 3 5 7 G 1 1 G 2 1 G 3 1 Q 1 C 2 Q 2 Q 3
 

Sample Output
3 0 1
 

Author
wangjing1111
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-26 09:06:39, Gzip enabled