Problems > Two Choices Each

Two Choices Each

Difficulty: 2100 4000 ms 128 MB

graphs 2-sat scc

N boolean variables must satisfy M clauses, each an OR of two literals (3 -5 means x3 OR NOT x5). Is the formula satisfiable?

Input: the first line has N and M; each of the next M lines has two non-zero integers a b (negative = negated variable).

Output: YES or NO.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ M ≤ 2×105

Sample Tests

Input 1
2 3
1 2
-1 2
-2 1
Output 1
YES
Input 2
1 2
1 1
-1 -1
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.