题目描述
Problem Description
There is a rooted tree with $ N $ vertices. Each vertex is numbered from $ 1 $ to $ N $, with vertex $ 1 $ being the root. The parent of vertex $ i $ $(2 \leq i \leq N)$ is $ P_i $.
Each vertex has a toy box. Also, there is a person at each vertex.
Initially, the toy box at vertex $ i $ contains $ A_i $ toys.
The person at vertex $ i $ aims to collect $ C_i $ toys. Here,
- The person at vertex $ i $ can choose some vertices from the subtree rooted at vertex $ i $ and take any number of toys from each chosen vertex.
Determine if it is possible for everyone to achieve their goals simultaneously. (Note that the same toy cannot be taken by multiple people.)
Additionally, $ Q $ queries are given. In the $ i $-th query, integers $ t_i, v_i, x_i $ are given, and the values are changed as follows:
- If $ t_i = 1 $, change the value of $ A_{v_i} $ to $ x_i $.
- If $ t_i = 2 $, change the value of $ C_{v_i} $ to $ x_i $.
After each query, determine if it is possible for everyone to achieve their goals simultaneously at that point.
Note that in determining whether everyone's goals can be achieved simultaneously, no actual movement of toys occurs. (That is, each determination is considered independently.)
Input Format
The input is given from the standard input in the following format:
$ N $ $ P_2 $ $\cdots$ $ P_N $ $ A_1 $ $\cdots$ $ A_N $ $ C_1 $ $\cdots$ $ C_N $ $ Q $ $ t_1 $ $ v_1 $ $ x_1 $ $ t_2 $ $ v_2 $ $ x_2 $ $ : $ $ t_Q $ $ v_Q $ $ x_Q $
Output Format
For each point in time, output Yes if it is possible for everyone to achieve their goals simultaneously, and No if it is not possible, each on a new line.
That is, output the answer for the initial state on the first line, and the answer for the state after the $ i $ $(1 \leq i \leq Q)$ query on the $ i + 1 $ line.
Sample Input and Output
Sample Input #1
3
1 1
2 1 3
3 1 2
2
1 1 1
2 3 1
Sample Output #1
Yes
No
Yes
Sample Input #2
5
1 2 1 3
1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1
1
1 1 1
Sample Output #2
Yes
Yes
Sample Input #3
5
1 2 2 2
109102235 645590056 708566822 497603443 131863700
50073184 441114664 164994352 304489019 158100373
8
1 5 692234112
1 3 610338520
2 4 818442884
2 4 164762830
2 4 923652447
2 4 197720766
1 1 779302743
1 1 222486377
Sample Output #3
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Notes/Hints
Constraints
- $1 \leq N \leq 10^5$
- $1 \leq P_i < i$ $(2 \leq i \leq N)$
- $1 \leq A_i \leq 10^9$
- $1 \leq C_i \leq 10^9$
- $1 \leq Q \leq 10^5$
- $t_i \in \{ 1, 2 \}$
- $1 \leq v_i \leq N$
- $1 \leq x_i \leq 10^9$
- All inputs are integers
Sample Explanation 1
Initially,
- The person at vertex $ 1 $ can take $ 2 $ toys from the toy box at vertex $ 1 $ and $ 1 $ toy from the toy box at vertex $ 3 $.
- The person at vertex $ 2 $ can take $ 1 $ toy from the toy box at vertex $ 2 $.
- The person at vertex $ 3 $ can take $ 2 $ toys from the toy box at vertex $ 3 $.
After the first query, the number of toys in the toy box at vertex $ 1 $ changes from $ 2 $ to $ 1 $. In this case, it is not possible for everyone to achieve their goals simultaneously.
After the second query, the number of toys the person at vertex $ 3 $ wants changes from $ 2 $ to $ 1 $. In this case,
- The person at vertex $ 1 $ can take $ 1 $ toy from the toy box at vertex $ 1 $ and $ 2 $ toys from the toy box at vertex $ 3 $.
- The person at vertex $ 2 $ can take $ 1 $ toy from the toy box at vertex $ 2 $.
- The person at vertex $ 3 $ can take $ 1 $ toy from the toy box at vertex $ 3 $.
Sample Explanation 2
The total number of toys can be very large.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分