CF1010D.Mars rover

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 11 , 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 ( 22 inputs), OR ( 22 inputs), XOR ( 22 inputs), NOT ( 11 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.

输入格式

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

The ii -th of the next nn lines contains a description of ii -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 ( 00 or 11 ), otherwise follow the indices of input vertices of this element: "AND", "OR", "XOR" have 22 inputs, whereas "NOT" has 11 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 11 .

输出格式

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.

输入输出样例

  • 输入#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
    

    输出#1

    10110

说明/提示

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

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

If Natasha changes the input bit 22 to 00 , then the output will be 11 .

If Natasha changes the input bit 33 to 00 , then the output will be 00 .

If Natasha changes the input bit 66 to 11 , then the output will be 11 .

If Natasha changes the input bit 88 to 00 , then the output will be 11 .

If Natasha changes the input bit 99 to 00 , then the output will be 00 .

首页