2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) |
---|
Finished |
Consider a simple single-bit boolean register that supports two operations:
The initial state of the register is false. Suppose there were $$$n$$$ operations $$$op_i$$$ (for $$$1 \le i \le n$$$) where at most two operations returned true. Also, we are given the partial order of operations as a directed acyclic graph (DAG): an edge $$$i \rightarrow j$$$ means that $$$op_i$$$ happened before $$$op_j$$$. 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 $$$n$$$ — the number of operations ($$$1 \le n \le 10^5$$$). In the following $$$n$$$ lines, you are given operations in the format "type result", where type is either "set" or "unset" and result is either "true" or "false". It is guaranteed that at most two operations have "true" results.
In the next line, you are given an integer $$$m$$$ — the number of arcs of the DAG ($$$0 \le m \le 10^5$$$). In the following $$$m$$$ lines, you are given arcs — pairs of integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq n$$$; $$$a \neq b$$$). Each arc indicates that operation $$$op_a$$$ happened before operation $$$op_b$$$.
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 $$$-1$$$.
5set trueunset trueset falseunset falseunset false21 45 2
5 1 3 2 4
3unset trueunset falseset true0
2 3 1
2unset falseset true12 1
-1
2unset falseset false0
-1
Name |
---|