#P12095. [NERC2024] DAG Serialization

    ID: 12013 Type: RemoteJudge 3000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>2024Special JudgeICPCNERC/NEERC

[NERC2024] DAG Serialization

题目描述

Consider a simple single-bit boolean register that supports two operations:

  • set\textbf{set} --- sets the register to true\textbf{true} if it was false\textbf{false}, and returns true\textbf{true}; otherwise, it returns false\textbf{false};
  • unset\textbf{unset} --- sets the register to false\textbf{false} if it was true\textbf{true}, and returns true\textbf{true}; otherwise, it returns false\textbf{false}.

The initial state of the register is false\textbf{false}. Suppose there were nn operations opiop_i (for 1in1 \le i \le n) where at most two operations returned true\textbf{at most two operations returned true}. Also, we are given the partial order of operations as a directed acyclic graph (DAG): an edge iji \rightarrow j means that opiop_i happened before opjop_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 nn --- the number of operations (1n1051 \le n \le 10^5). In the following nn lines, you are given operations in the format typeresult\textit{type} \textit{result}, where type\textit{type} is either set\texttt{set} or unset\texttt{unset} and result\textit{result} is either true\texttt{true} or false\texttt{false}. It is guaranteed that at most two operations have true\texttt{true} results.

In the next line, you are given an integer mm --- the number of arcs of the DAG (0m1050 \le m \le 10^5). In the following mm lines, you are given arcs --- pairs of integers aa and bb (1a,bn1 \leq a, b \leq n; aba \neq b). Each arc indicates that operation opaop_a happened before operation opbop_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-1.

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