Problem d. The Pure Vessel ≡

Author:Pavel Mesenev   Time limit:3 sec
Input file:Standard input   Memory limit:512 Mb
Output file:Standard output  
Maximum points:100  

Statement

THEPURE VESSEL

Beneath a dying kingdom, a pale king shapes vessels from the Void. Each vessel is shaped one trait at a time — mind, will, voice — and every trait is either granted or withheld. The king has written his demands: every demand lists a few traits, and a vessel answers the demand if at least one of them comes out the way the king wants. A vessel that fails even one demand is cast into the Abyss.

The king needs one vessel that answers every demand — or the certainty that none can, before the Abyss fills. He has been deceived before: a vessel declared pure must withstand every demand when inspected.

Input format

The first line contains n and m, the numbers of variables and clauses. Each of the next m lines lists the literals of one clause and ends with 0. A positive number i denotes xi, and  − i denotes xi.

Output format

If the formula is satisfiable, print SAT on the first line and n values 0 or 1 — the values of x1,…,xn — on the second. Any satisfying assignment is accepted. Otherwise print UNSAT.

Constraints

1 ≤ n ≤ 200, 1 ≤ m ≤ 2000. Each clause contains 1 to 6 literals, and a variable occurs in a clause at most once.

Tests are grouped. The points of a group are awarded only if every test in the group passes. Groups mix satisfiable and unsatisfiable formulas.

The last three groups (24 points) are boss tests. No author's branching solution passes them, the reference included; they reward ideas beyond the lecture.

Sample tests

No. Standard input Standard output
1
4 4
1 2 -3 0
-1 3 0
-2 4 0
-4 -1 0
SAT
0 1 0 1
2
3 8
-1 2 3 0
1 -2 3 0
1 2 -3 0
-1 -2 -3 0
1 2 3 0
-1 -2 3 0
-1 2 -3 0
1 -2 -3 0
UNSAT

0.291s 0.009s 18