rt
#include <bits/stdc++.h>
#define maxn 1000100
using namespace std;
//板子代码来自:https://www.luogu.com.cn/blog/85514/post-2-sat-xue-xi-bi-ji
//暴力第二种解法为数位dp的感觉
int dfn[maxn];
int low[maxn];
int cnt;
int tot;
int outdegree[maxn];
int num[maxn];
int s[maxn];
int top;
vector<int> G[maxn];
bool vis[maxn];
int belong[maxn];
int n, m;
void tarjan(int x) {
int c;
low[x] = dfn[x] = ++cnt;
s[++top] = x;
vis[x] = true;
for (unsigned int i = 0; i < G[x].size(); i++) {
c = G[x][i];
if (!dfn[c]) {
tarjan(c);
low[x] = min(low[x], low[c]);
} else if (!vis[c]) {
low[x] = min(dfn[c], low[x]);
}
}
if (dfn[x] == low[x]) {
tot++;
c = -1;
while (x != c) {
//TODO
c = s[top--];
belong[c] = tot;
num[tot]++;
vis[c] = false;
}
}
}
int i, j, a, b;
int main() {
memset(vis, false, sizeof vis);
cin >> n >> m;
for (int k = 1; k <= m; k++) {
cin >> i >> a >> j >> b;
G[i + n * b].push_back(j + n * (b ^ 1));
G[j + n * b].push_back(i + n * (a ^ 1));
// G[i + (n & a)].push_back(j +)
}
for (i = 1; i <= 2 * n; i++)
if (!dfn[i]) tarjan(i);
for (i = 1; i <= n; i++) {
if (belong[i] == belong[i + n]) {
cout << "IMPOSSIBLE";
return 0;
}
}
cout << "POSSIBLE" << endl;
for (i = 1; i <= n; i++) {
if (belong[i] < belong[i + n])cout << "0 ";
else cout << "1 ";
}
return 0;
}
验证码acp6寄