#SGM0000087. Danil và công việc bán thời gian (Danil and a Part-time Job)
Danil và công việc bán thời gian (Danil and a Part-time Job)
Danil and a Part-time Job
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
Each vertex is a room whose light is either on or off. The command pow v flips every light in the subtree of , and get v asks how many lights are on in that subtree.
Input
The first line contains . The second line contains the parents ; it is empty when . The third line contains the initial light states. The fourth line contains . The next lines contain either pow v or get v.
Output
For every get command, print the number of lights that are on in the subtree.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
- Every light state is 0 or 1.
Example
Input
1
0
8
pow 1
get 1
pow 1
get 1
pow 1
pow 1
get 1
get 1
Output
1
0
0
0
Explanation
Each pow 1 flips the only light, and each get 1 prints its current state.