2-SAT Satisfiability
Time limit1sMemory limit256 MB
Decide whether N boolean variables admit values that satisfy all M two-literal clauses.
Problem
2-SAT asks how to pick a value for each of the boolean variables so that a 2-CNF formula becomes true.
A 2-CNF formula looks like . Each parenthesized part is a clause, and a clause joins two variables with . Here is OR, is AND, and is NOT.
You are 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. For , , and , no value of makes true.
Input
The first line holds the number of variables () and the number of clauses (). Each of the next lines holds one clause as two integers and (). A positive means and a negative means . The same rule applies to .
Output
Print 1 on the first line if can be made true, and 0 otherwise.