DAG Serialization
시간 제한3초메모리 제한2048 MB
각각 반환값이 정해진 set과 unset 연산들이 DAG의 부분 순서로 주어질 때, 레지스터 동작과 반환값을 모두 만족하는 위상 순서를 찾거나 불가능함을 판정한다.
문제
Consider a simple single-bit boolean register that supports two operations:
- set --- sets the register to true if it was false, and returns true; otherwise, it returns false;
- unset --- sets the register to false if it was true, and returns true; otherwise, it returns false.
The initial state of the register is false. Suppose there were operations (for ) where at most two operations returned true. 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 "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 --- 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 .