Codeforces Round 499 (Div. 2)
F
Mars rover
Codeforces
未评级
原题
← E→
翻译中…

Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, which is output. One bit is fed to each input. One bit is returned at the output.

翻译中…

There are four types of logical elements: AND ($2$ inputs), OR ($2$ inputs), XOR ($2$ inputs), NOT ($1$ input). Logical elements take values from their direct descendants (inputs) and return the result of the function they perform. Natasha knows the logical scheme of the Mars rover, as well as the fact that only one input is broken. In order to fix the Mars rover, she needs to change the value on this input.

翻译中…

For each input, determine what the output will be if Natasha changes this input.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 10^6$) — the number of vertices in the graph (both inputs and elements).

翻译中…

The $i$-th of the next $n$ lines contains a description of $i$-th vertex: the first word "AND", "OR", "XOR", "NOT" or "IN" (means the input of the scheme) is the vertex type. If this vertex is "IN", then the value of this input follows ($0$ or $1$), otherwise follow the indices of input vertices of this element: "AND", "OR", "XOR" have $2$ inputs, whereas "NOT" has $1$ input. The vertices are numbered from one.

翻译中…

It is guaranteed that input data contains a correct logical scheme with an output produced by the vertex $1$.

翻译中…

Output

翻译中…

Print a string of characters '0' and '1' (without quotes) — answers to the problem for each input in the ascending order of their vertex indices.

翻译中…

Note

翻译中…

The original scheme from the example (before the input is changed):

翻译中…

image

翻译中…

Green indicates bits '1', yellow indicates bits '0'.

翻译中…

If Natasha changes the input bit $2$ to $0$, then the output will be $1$.

翻译中…

If Natasha changes the input bit $3$ to $0$, then the output will be $0$.

翻译中…

If Natasha changes the input bit $6$ to $1$, then the output will be $1$.

翻译中…

If Natasha changes the input bit $8$ to $0$, then the output will be $1$.

翻译中…

If Natasha changes the input bit $9$ to $0$, then the output will be $0$.

翻译中…

样例

Input #1
10
AND 9 4
IN 1
IN 1
XOR 6 5
AND 3 7
IN 0
NOT 10
IN 1
IN 1
AND 2 8
Output #1
10110
InputCopy OutputCopy
题目信息
题号
1011F
时间限制
5 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。