#P10722. [GESP202406 六级] 二叉树

    ID: 12204 远端评测题 1000ms 512MiB 尝试: 7 已通过: 5 难度: 5 上传者: 标签>树形数据结构2024图遍历树的遍历GESP

[GESP202406 六级] 二叉树

Background

Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1154.

Problem Description

Xiao Yang has a binary tree with nn nodes, and the root node is labeled 11. Each node in this binary tree is either white or black. Then Xiao Yang will perform qq operations on this binary tree. In each operation, Xiao Yang chooses a node and flips the color of every node in the subtree rooted at that node, meaning black becomes white and white becomes black.

Xiao Yang wants to know the color of each node after all qq operations are completed.

Input Format

The first line contains a positive integer nn, representing the number of nodes in the binary tree.

The second line contains (n1)(n-1) positive integers. The ii-th (1in11\le i\le n-1) number indicates the label of the parent of node (i+1)(i+1). The data guarantees that the tree is a binary tree.

The third line contains a 01\texttt{01} string of length nn. From left to right, if the ii-th (1in1\le i\le n) character is 0\texttt{0}, it means node ii is white; otherwise, it is black.

The fourth line contains a positive integer qq, representing the number of operations.

The next qq lines each contain a positive integer aia_i (1ain1\le a_i\le n), representing the label of the node chosen in the ii-th operation.

Output Format

Output a single line containing a 01\texttt{01} string of length nn, representing the color of each node after all qq operations are completed. From left to right, if the ii-th (1in1\le i\le n) character is 0\texttt{0}, it means node ii is white; otherwise, it is black.

6
3 1 1 3 4
100101
3
1
3
2
010000

Hint

Sample Explanation

After the first operation, the node colors are: 011010\texttt{011010}.

After the second operation, the node colors are: 000000\texttt{000000}.

After the third operation, the node colors are: 010000\texttt{010000}.

Constraints

Subtask ID Score nn qq Special Condition
11 2020 105\le 10^5 For all i2i\ge 2, the parent of node ii is node i1i-1.
22 4040 1000\le 1000
33 105\le 10^5

For all testdata, it is guaranteed that n,q105n,q\le 10^5.

Translated by ChatGPT 5