Given 2-SAT clauses, find the minimum number of clauses of the form (p_a OR p_b) to add so the whole formula becomes unsatisfiable, or -1.
Medium7GraphDFSGreedyImplementationNo attempts yetTime limit2sMemory limit512 MBA computer scientist usually tries to satisfy a set of constraints. This time you do the opposite and make a list of logical statements unsatisfiable.
You are given a list of logical statements of the following form:
p1∨p2,¬p2∨p3,p3∨¬p4.
Each pi is a proposition that is either true or false. The disjunction operator ∨ is read as logical OR. The symbol ¬ is negation, which flips the value of the proposition that follows it from true to false and from false to true.
To satisfy a list of logical statements, you must assign true or false to each proposition so that every disjunction in the list evaluates to true.
Your task is to add disjunctions to the list so that the whole list becomes unsatisfiable. The disjunctions you add cannot use the negation symbol.
Every disjunction, both the given ones and the ones you add, has exactly two terms.
The first line contains two integers n and m separated by a space (1≤n,m≤2000). Here n is the number of propositions and m is the number of disjunctions.
Each of the next m lines contains two integers ai and bi separated by a space (1≤∣ai∣,∣bi∣≤n), describing the two propositions of the i-th disjunction. A positive ai means the proposition pai, and a negative ai means the negated proposition ¬p∣ai∣. Read bi the same way.
The second sample input corresponds to the following list of logical statements:
p1∨p2,¬p1∨¬p3,¬p2∨p3,p3∨¬p4,¬p2∨¬p3.
Print on a single line one integer, the minimum number of disjunctions you must add to make the list unsatisfiable. If the list cannot be made unsatisfiable, print −1 instead. Each disjunction you add consists of two propositions, the two propositions do not have to be distinct, and neither of them may be negated.
In the second sample, adding the disjunction p2∨p2 makes the list unsatisfiable.