| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 2 | 0 | 0 | 0.000% |
Lora’s mansion is being invaded by rats. Luckily we can describe the rooms in Lora’s mansion as a rooted tree with N nodes, numbered from 1 to N, with node 1 being the root.
Initially, no node is infested. Various events happen consecutively, each being one of the following 4 types:
The subtree of node X is defined as the set of nodes that contains X as well as any of its direct or indirect successors (see the sample test for better understanding).
Help Lora by writing a program that processes each of the events and correctly computes the answers to all events of type 4.
The first line of the standard input contains a single integer N – the number of nodes in the tree. The second line contains N - 1 numbers, the i-th of which is pi+1 – the father of node i + 1. The third line contains the number of events Q. Each of the following Q lines contains two integers, describing an event in one of the aforementioned formats.
For every event of type 4 output a single line containing one integer – the number of infested nodes in the subtree.
5 1 1 3 3 8 1 3 2 5 4 1 1 1 2 1 4 3 3 1 4 3
1 2 1
The events have the following effect: