#P9798. [NERC 2018] Harder Satisfiability
[NERC 2018] Harder Satisfiability
Background
Translated from Problem H of NERC 2018.
Problem Description
We define a “fully quantified Boolean 2-CNF formula” (abbreviated as 2-CNF) as an expression of the form . Each has only two possible values: the “universal quantifier” and the “existential quantifier” . Then is a conjunction ( operation) of clauses of the form ( operation), where and are not necessarily different and are not necessarily negated (or ). Since the 2-CNF formula is fully specified, it has no free variables (that is, the final value is fixed as either or ).
To evaluate a 2-CNF formula, we can use the following simple recursive algorithm:
-
If there is no quantifier (i.e., no or ), return the value of the remaining expression.
-
Otherwise, recursively compute: , where .
-
If the current quantifier is , return ( operation). Otherwise, if it is , return .
Input Format
The first line contains an integer , the number of test cases.
Then follow test cases. For each test case, the first line contains two integers and . Here, is the number of quantifiers, and is the number of clauses in .
The next line contains a string of length . If A, then ; if E, then .
In the next lines, each line contains two integers . If , then the literal is ; if , then the literal is . The same applies to .
Output Format
For each test case, if the 2-CNF formula is true, output TRUE; otherwise output FALSE.
3
2 2
AE
1 -2
-1 2
2 2
EA
1 -2
-1 2
3 2
AEA
1 -2
-1 -3
TRUE
FALSE
FALSE
Hint
The testdata guarantees , , and .
The first 2-CNF formula can be simplified to $\forall x_1 \exists x_2(x_1 \lor \overline{x_2}) \land (\overline{x_1} \lor x_2) = \forall x_1 \exists x_2 x_1 \oplus x_2$. For any , there exists that makes the result true.
The second 2-CNF changes the order of the formula. For any , you can choose , making the expression FALSE.
The third expression is $\forall x_1 \exists x_2 \forall x_3 (x_1 \lor \overline{x_2}) \land (\overline{x_1} \lor \overline{x_3})$. If we set and , then there is no value of that can make the sentence evaluate to true, so the formula is false.
Translated by ChatGPT 5