luogu#P4782. 【模板】2-SAT

    ID: 3797 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论Special JudgeO2优化2-SAT强连通分量

【模板】2-SAT

Problem Description

There are nn Boolean variables x1xnx_1\sim x_n, and mm constraints that must be satisfied. Each constraint has the form: “xix_i is true / false or xjx_j is true / false”. For example, “x1x_1 is true or x3x_3 is false”, “x7x_7 is false or x2x_2 is false”.

The goal of the 2-SAT problem is to assign a value to each variable so that all constraints are satisfied.

Input Format

The first line contains two integers nn and mm, with the meanings as described above.

The next mm lines each contain four integers ii, aa, jj, bb, meaning “xix_i is aa or xjx_j is b(b” (a, b\in {0,1}$).

Output Format

If there is no solution, output IMPOSSIBLE.

Otherwise output POSSIBLE, and on the next line output nn integers x1xnx_1\sim x_n (xi{0,1}x_i\in\{0,1\}), representing a constructed solution.

3 1
1 1 3 0
POSSIBLE
0 0 0

Hint

1n,m1061\leq n, m\leq 10^6. The first 33 test points check for small mistakes, and the remaining 55 test points check efficiency.

Since the testdata is generated randomly, it may contain tricky cases such as 10 0 10 0, but the official solution written in the most standard way did not make mistakes. The hints about what each test point is checking are in the official solution.

Translated by ChatGPT 5