2-SAT Assignment

No attempts yetTime limit1sMemory limit256 MB

Problem

2-SAT asks whether the boolean variables x1,x2,,xNx_1, x_2, \dots, x_N can be assigned values that make a given 2-CNF formula true.

A 2-CNF formula looks like (xy)(¬yz)(x¬z)(zy)(x \lor y) \land (\lnot y \lor z) \land (x \lor \lnot z) \land (z \lor y). Each parenthesized part is a clause. A clause joins two literals with \lor, and a literal is a variable or the negation of a variable. Here \lor is OR, \land is AND, and ¬\lnot is NOT.

Given the number of variables NN, the number of clauses MM, and the formula ff, decide whether ff can be made true, and give the values of the variables when it can.

For N=3N = 3, M=4M = 4, and f=(¬x1x2)(¬x2x3)(x1x3)(x3x2)f = (\lnot x_1 \lor x_2) \land (\lnot x_2 \lor x_3) \land (x_1 \lor x_3) \land (x_3 \lor x_2), setting x1x_1 false, x2x_2 false, and x3x_3 true makes ff true. For N=1N = 1, M=2M = 2, and f=(x1x1)(¬x1¬x1)f = (x_1 \lor x_1) \land (\lnot x_1 \lor \lnot x_1), no value of x1x_1 makes ff true.

Input

The first line contains the number of variables NN (1N201 \le N \le 20) and the number of clauses MM (1M1001 \le M \le 100).

Each of the next MM lines holds one clause as two integers ii and jj (1i,jN1 \le |i|, |j| \le N). A positive ii means the literal xix_i, and a negative ii means the literal ¬xi\lnot x_{-i}. The same variable may appear twice in one clause, and the same clause may be given more than once.

Output

Print 1 on the first line if ff can be made true, and 0 if it cannot.

If it can, print the values of x1x_1 through xNx_N in order on the second line, separated by single spaces. Write 1 for true and 0 for false.

When several assignments make ff true, print only the one whose sequence (x1,x2,,xN)(x_1, x_2, \dots, x_N) is lexicographically smallest. That is, walk the variables in order: keeping the values already fixed, set the current variable to 0 if the remaining variables can still make ff true, and set it to 1 only when they cannot.