#P12095. [NERC2024] DAG Serialization
[NERC2024] DAG Serialization
题目描述
Consider a simple single-bit boolean register that supports two operations:
- --- sets the register to if it was , and returns ; otherwise, it returns ;
- --- sets the register to if it was , and returns ; otherwise, it returns .
The initial state of the register is . Suppose there were operations (for ) where . Also, we are given the partial order of operations as a directed acyclic graph (DAG): an edge means that happened before . You are asked whether it is possible to put these operations in some linear sequential order that satisfies the given partial order and such that if operations are applied to the register in that order, their results are the same as given.
输入格式
In the first line, you are given an integer --- the number of operations (). In the following lines, you are given operations in the format , where is either or and is either or . It is guaranteed that at most two operations have results.
In the next line, you are given an integer --- the number of arcs of the DAG (). In the following lines, you are given arcs --- pairs of integers and (; ). Each arc indicates that operation happened before operation .
输出格式
Print any linear order of operations that satisfies the DAG constraints and ensures the results of the operations match the ones given in the input. If a correct operation order does not exist, print .
5
set true
unset true
set false
unset false
unset false
2
1 4
5 2
5 1 3 2 4
3
unset true
unset false
set true
0
2 3 1
2
unset false
set true
1
2 1
-1
2
unset false
set false
0
-1