2-SAT Satisfiability
InterviewTime limit1sMemory limit256 MB
Decide whether N boolean variables admit an assignment satisfying all M two-literal clauses.
- Level
Easy3 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
2-SAT asks whether boolean variables can be assigned values that make a 2-CNF formula true.
A 2-CNF formula looks like . Each parenthesized part is a clause, and a clause is two variables joined by . Here is OR, is AND, and is NOT.
Given the number of variables , the number of clauses , and the formula , write a program that decides whether can be made true.
For example, take , , and . Setting to false, to false, and to true makes true. With , , and , no value of makes true.
Input
The first line has the number of variables () and the number of clauses (). Each of the next lines has one clause, given as two integers and (). A positive integer means or , and a negative integer means or .
Output
Print 1 on the first line if can be made true, and 0 otherwise.