题目描述
Problem Description
You are given a rooted tree with $ N $ vertices. Each vertex is numbered from $ 1 $ to $ N $, and vertex $ 1 $ is the root of the tree. All edges are undirected, and the parent of the $ i $th vertex ( $ 2 ≦ i ≦ N $ ) is $ p_i $.
Initially, each vertex is painted either white or black. The initial color of the $ i $th vertex ( $ 1 ≦ i ≦ N $ ) is white if $ C_i = 0 $ and black if $ C_i = 1 $.
You will be given $ Q $ queries to process in order. There are two types of queries, with the following input format and content:
1 u: Invert the color of all vertices in the subtree rooted at vertex $ u $.2 u v: OutputYESif it is possible to travel from vertex $ u $ to vertex $ v $ by alternating between white and black vertices, otherwise outputNO. The initial color does not matter.
Input Format
The input is provided from standard input in the following format:
$ N $ $ p_2 $ $ p_3 $ $ : $ $ p_N $ $ C_1 $ $ C_2 $ $ : $ $ C_N $ $ Q $ $ query_1 $ $ query_2 $ $ : $ $ query_Q $
Output Format
For each query with the format 2 u v, output the answer in a single line in the order the queries are given.
Sample Input and Output
Sample Input #1
6
1
1
2
2
3
0
1
0
0
1
1
10
2 4 1
2 4 3
2 1 2
1 2
2 4 1
1 3
1 5
2 1 6
1 1
2 5 4
Sample Output #1
YES
NO
YES
NO
YES
YES
Sample Input #2
7
1
2
3
3
5
6
0
0
1
0
0
1
1
7
2 1 4
2 4 2
2 4 5
2 4 6
2 6 1
2 7 1
2 2 6
Sample Output #2
NO
YES
YES
YES
NO
NO
YES
Sample Input #3
2
1
0
1
11
2 1 2
2 2 1
1 2
2 1 2
2 2 1
1 1
2 1 2
2 2 1
1 2
2 1 2
2 2 1
Sample Output #3
YES
YES
NO
NO
NO
NO
YES
YES
Sample Input #4
5
1
2
3
4
0
1
0
1
0
11
2 1 2
2 1 4
2 3 1
2 5 1
2 4 5
1 3
2 1 2
2 1 4
2 3 1
2 5 1
2 4 5
Sample Output #4
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
Sample Input #5
9
4
2
6
8
1
4
1
8
0
0
1
0
0
1
1
1
0
2
2 9 8
2 9 4
Sample Output #5
YES
YES
Notes/Hints
Constraints
- All input values are integers.
- $ 2 ≦ N ≦ 10^5 $
- $ 1 ≦ p_i ≦ N $
- $ C_i = 0 $ or $ 1 $
- $ 1 ≦ Q ≦ 10^5 $
- The input rooted tree is always connected.
- For query
1 u, $ 1 ≦ u ≦ N $. - For query
2 u v, $ 1 ≦ u, v ≦ N $ and $ u ≠ v $. - At least one query with the format
2 u vis guaranteed to exist.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分