#Lutece3211. 布尔公式
布尔公式
Migrated from Lutece 3211 布尔公式
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
lllei 想要帮你复习离散数学,于是有了以下问题:
一个完全量化的 2-CNF 是指一个满足以下条件的布尔公式:
- 该公式具有以下形式:
- 每个 都是量词,意即 代表 (任意),或者 (存在)
- 首先是一个合取范式,并且每个子句都是二元的,即类似于这种形式:$(s_1 \lor t_1) \land (s_2 \lor t_2) ... (s_n \lor t_n)$。 的子句有 个。
由于其公式是完全量化的(没有自由变元),该公式的值是确定的。
现在给你一个完全量化的 2-CNF,请你求出该公式的值。
Input
第一行一个整数,代表数据组数。
接下来对于每一组数据:
第一行有两个整数 代表变元数量,子句数量。
接下来是一个具有 个字符的字符串,对于第 个字符,若为 A
,代表 为 ;若为 E
,代表 为 。
接下来 行,每行两个整数 ,代表第 个子句的形式:
若 ,则代表 ;若 ,则代表 。 的含义类似。
Output
对于每一组数据,输出 TRUE
或者 FALSE
,代表每组公式的值。
Samples
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
Constraints
保证 之和不超过 ,保证 之和不超过
Note
第一组数据代表的 2-CNF 为:
$$\forall x_1 \exists x_2 (x_1 \lor \overline{x_2}) \land (\overline{x_1} \lor x_2) $$第二组数据代表的 2-CNF 为:
$$\exists x_1 \forall x_2 (x_1 \lor \overline{x_2}) \land (\overline{x_1} \lor x_2) $$第三组数据代表的 2-CNF 为:
$$\forall x_1 \exists x_2 \forall x_3 (x_1 \lor \overline{x_2}) \land (\overline{x_1} \lor \overline{x_3}) $$Resources
2024 UESTC ICPC Training for Graph