#P4332. [SHOI2014] 三叉神经树
[SHOI2014] 三叉神经树
Description
Computational neuroscience, as an emerging interdisciplinary field, has been a research hotspot in recent years. A kind of neural tissue called SHOI has attracted great attention because of its close relationship with a recently discovered compound, SHTSC.
A SHOI tissue consists of several SHOI cells forming a strict tree structure. Each SHOI cell has exactly one output terminal, called an axon. Except for a special SHOI cell called the root cell whose output serves as the output of the entire tissue, the axons of all other cells connect to their parent SHOI cell. Each cell also has exactly three input terminals, called dendrites, which receive information from its child cells or from other neural tissues. The signaling mechanism of SHOI cells is simple, with only and . Each SHOI cell outputs the majority value among the three input signals, i.e., whichever of or appears more times among its three inputs.
You are given the structure of a SHOI tissue and the changes of external neural inputs. Please simulate the output of the SHOI tissue.
Input Format
- The first line contains an integer , the total number of SHOI cells. Cells are numbered , and cell is the root cell.
- The next lines each contain three integers , describing the dendrite connections of cells , respectively. If , it connects to the axon of cell . If , it connects to the external input with index . The input guarantees that the given SHOI tissue is valid, and for each cell the three are pairwise distinct.
- The next line contains integers (each or ), giving the initial values of the external inputs in the order of indices .
- The next line contains an integer , the number of operations.
- The next lines each contain one integer , indicating that the external input with index (where ) toggles its value.
Output Format
Output lines. For the -th change of an external input, print one integer: the output of the root cell after this change.
3
2 3 4
5 6 7
8 9 10
0 0 0 0 1 1 1
5
4
4
5
6
8
1
0
0
1
1
Hint
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号