#1375
Unrated
Harder Satisfiability
시간 제한
3s
메모리 제한
512MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

A fully quantified boolean 2-CNF formula is a formula in the following form: Q1x1QnxnF(x1,,xn)Q_1 x_1 \, \ldots Q_n x_n \, F(x_1, \ldots, x_n). Each QiQ_i is one of two quantifiers: a universal quantifier \forall ("for all"), or an existential quantifier \exists ("exists"); and FF is a conjunction (boolean AND) of mm clauses sts \vee t (boolean OR), where ss and tt are some variables (not necessarily different) with or without negation. This formula has no free variables, so it evaluates to either true or false. We can evaluate a given fully quantified formula with a simple recursive algorithm:

  1. If there are no quantifiers, return the remaining expression's value of true or false.
  2. Otherwise, recursively evaluate formulas: Fz=Q2x2QnxnF(z,x2,,xn)F_z = Q_2 x_2 \ldots Q_n x_n \, F(z, x_2, \ldots, x_n) for z=0,1z = 0, 1.
  3. If Q1=Q_1 = \exists return F0F1F_0 \vee F_1; otherwise if Q1=Q_1 = \forall return F0F1F_0 \wedge F_1.

You are given some fully quantified boolean 2-CNF formulas. Find out if they are true or not.

입력

The first line of the input contains a single integer tt (1t1051 \le t \le 10^5) — the number of test cases.

The first line of a test case contains two integers nn and mm (1n,m1051 \le n, m \le 10^5) — the number of variables and the number of clauses in FF. The next line contains a string ss with nn characters describing the quantifiers. If si=s_i = 'A' then QiQ_i is a universal quantifier \forall, otherwise if si=s_i = 'E' then sis_i is an existential quantifier \exists.

Next mm lines describe clauses in FF. Each line contains two integers uiu_i and viv_i (nui,vin-n \le u_i, v_i \le n; ui,vi0u_i, v_i \neq 0). If ui1u_i \ge 1 then the first variable in the ii-th clause is xuix_{u_i}. Otherwise, if ui1u_i \le -1 then the first variable is xui\overline{x_{-u_i}} (negation of xuix_{-u_i}). The second variable in the ii-th clause is similarly described by viv_i.

The sum of values of nn for all test cases does not exceed 10510^5; the sum of values of mm does not exceed 10510^5.

출력

For each test case output "TRUE" if the given formula is true or "FALSE" otherwise.

예제 입력 1

3
2 2
AE
1 -2
-1 2
2 2
EA
1 -2
-1 2
3 2
AEA
1 -2
-1 -3

예제 출력 1

TRUE
FALSE
FALSE

노트

The first sample corresponds to a formula x1x2(x1x2)(x1x2)=x1x2x1x2 \forall x_1 \, \exists x_2 \, (x_1 \vee \overline{x_2}) \wedge (\overline{x_1} \vee x_2) = \forall x_1 \, \exists x_2 \, \, x_1 \oplus x_2. For any x1x_1 we can choose x2=x1x_2 = \overline{x_1} making it true, hence the formula is true.

The second sample changes the order of quantifiers. Now the answer is "FALSE", because for any value of x1x_1 we can choose x2=x1x_2 = x_1 and the formula becomes false.

The third formula is x1x2x3(x1x2)(x1x3) \forall x_1 \, \exists x_2 \, \forall x_3 \, (x_1 \vee \overline{x_2}) \wedge (\overline{x_1} \vee \overline{x_3}). If we substitute x1=1x_1 = 1, x3=1x_3 = 1 then no assignment of x2x_2 can make the second clause true, so the formula is false.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.