Yet Satisfiability Again
Time limit1sMemory limit256 MB
Decide whether a CNF formula over at most 20 variables and 100 clauses has an assignment that satisfies every clause.
- Level
Easy3 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Alice recently started working at a hardware design company. One of her jobs is finding defects in fabricated integrated circuits, and that check reduces to deciding whether a single logical formula is satisfiable.
The formula is given in conjunctive normal form. The variables are through . A literal is a variable or its negation . A clause is a disjunction of literals, and the formula is the conjunction of all clauses.
Write a program that decides whether true and false can be assigned to the variables so that every clause is true at the same time.
Input
The first line contains the number of test cases . is not more than 5.
The first line of each test case contains the number of variables and the number of clauses (, ). Then lines follow, one clause per line.
Each clause is a disjunction of literals. A literal is or with . The disjunction operator is written as the character v and is separated from the literal on either side by a single space. The same variable may appear more than once in one clause, and both polarities of one variable may appear together.
Output
For each test case, print satisfiable on its own line if some assignment makes every clause true, and unsatisfiable otherwise.