G - Apple Tree
来源:互联网 发布:网络论坛 编辑:程序博客网 时间:2024/05/01 14:37
[Submit] [Go Back] [Status]
Description
There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree.
The tree has N forks which are connected by branches. Kaka numbers the forks by 1 to N and the root is always numbered by 1. Apples will grow on the forks and two apple won't grow on the same fork. kaka wants to know how many apples are there in a sub-tree, for his study of the produce ability of the apple tree.
The trouble is that a new apple may grow on an empty fork some time and kaka may pick an apple from the tree for his dessert. Can you help kaka?
Input
The first line contains an integer N (N ≤ 100,000) , which is the number of the forks in the tree.
The following N - 1 lines each contain two integers u and v, which means fork u and fork v are connected by a branch.
The next line contains an integer M (M ≤ 100,000).
The following M lines each contain a message which is either
"C x" which means the existence of the apple on fork x has been changed. i.e. if there is an apple on the fork, then Kaka pick it; otherwise a new apple has grown on the empty fork.
or
"Q x" which means an inquiry for the number of apples in the sub-tree above the fork x, including the apple (if exists) on the fork x
Note the tree is full of apples at the beginning
Output
Sample Input
31 21 33Q 1C 2Q 1
Sample Output
32
- G - Apple Tree
- Apple Tree
- Apple Tree
- Apple Tree
- Apple Tree
- Apple Tree
- The Apple Tree
- The Apple Tree
- POJ 3321 Apple Tree
- POJ 3321 Apple Tree
- Apple Tree(动态规划)
- poj 3321 Apple Tree
- poj3321---Apple Tree
- Binary Apple Tree
- POJ 3321 Apple Tree
- Poj 3321 Apple Tree
- poj 3321 apple tree
- POJ3321 Apple Tree
- Fedora15 显卡驱动程序的安装
- libxml2
- E - Frequent values
- 第七章:线程调度,优先级和关联性
- F - Billboard
- G - Apple Tree
- 解决Eclipse Java EE 结合Tomcat访问404错误!
- 2010年杭电计算机研究生复试---笔试编程
- H - Japan
- I - Matrix
- J - Necklace
- K - Mobile phones
- 汇率换算(android安卓版)
- tiny6410开发板的Linux系统修改IP地址