#P8383. [POI 2004] Bra
[POI 2004] Bra
Problem Description
Let us consider a circuit containing gates.
The gates are numbered from to . Each gate has several inputs and one output.
Each input and output can only be in one of three states: , , or . Each input is connected to the output of some gate, so the state of an input is equal to the state of the output it is connected to. Each output may be connected to any number of inputs.
Gates and are two special gates. The output of gate is always , and the output of gate is always .
The condition for a gate’s output state is as follows:
-
If the number of among its inputs is greater than the number of , then the output state is .
-
If the number of among its inputs is equal to the number of , then the output state is .
-
If the number of among its inputs is less than the number of , then the output state is .
-
For gates and , they output and respectively.
Now you are given the circuit information. Please write a program to determine the states of all gates whose states can be determined.
Input Format
The first line contains an integer .
The next lines describe the connections of the gates. Line describes the input terminals of gate : an integer indicating the number of its input terminals, followed by integers giving the indices of the gates connected to each input terminal.
Output Format
Output lines, representing the output states of the gates. If it can be determined, output the specific state value; otherwise output .
5
2 0 1
2 4 2
2 2 4
0
1
1/2
?
?
Hint
For all testdata, , . The testdata guarantees that the total number of input terminals over all gates does not exceed .
Translated by ChatGPT 5