#Lutece0574. High-level ancients
High-level ancients
Migrated from Lutece 574 High-level ancients
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Love8909 is keen on the history of Kingdom ACM. He admires the heroic undertakings of Lxhgww and Haibo. Inspired by those sagas, Love8909 picked up his courage and tried to build up his own kingdom. He named it as A230.
After hard working for several years, Love8909 is about to fulfill his dream. However, there is still one thing to do: setting up the defense network. As Kingdom EDC looks at territory and people of A230 fiercely as a tiger does, Love8909 has to make it as soon as possible.
The defense network Love8909 wants to use is the same as the one used by Lxhgww and Haibo. He also connects all cities with roads which form a tree structure, and the capital city is City , which is the root of this tree. Love8909 sends commands to inform cities to add soldiers. The command, being same to those of the ancients, with two values, and , means sending soldiers to City , sending soldiers to sons of City , sending soldiers to sons of sons of City and so on. Initially there are no soldiers in any city.
Love8909 may adjust the arrangement of soldiers ever and again. He asks questions about how many soldiers in the subtree rooted at City . A subtree rooted at City includes City itself and all of its descendants. As Love8909's military counselor, you are responsible to complete all his commands and answer his questions.
Input
The first line of the input will be an integer () indicating the number of cases.
For each case, the first line contains two integers: , representing the number of cities in A230 and number of operations given by love8909.
The next line lists integers, in which the number, denoted as , represents there is a road from City to City . Note that the City has been omitted. for .
Then lines follow, each gives an operation. Each operation belongs to either kind:
A X K
. An adding-soldier command.Q X
. A question about how many soldiers in the subtree rooted at City .
We guarantee that the cities form a rooted tree and the root is at City , which is the capital.
, , , .
Output
For each case, print Case #k:
first in a single line, in which represents the case number which starts from . Then for each Query X
operation, print the answer in a single line.
Samples
1
7 10
1 1 2 2 5 5
Q 1
A 2 1
Q 1
Q 2
Q 5
A 5 0
Q 5
A 3 1
Q 1
Q 2
Case #1:
0
11
11
8
10
14
13
Note
Huge input/output. Please use scanf/printf
for C/C++
.
In the first case, adding soldier to City leads to soldiers needed in total.
Resources
10th UESTC Programming Contest Final