// #define int long long #define DEBUG(a) cerr << #a << " = " << a << '\n' #define x first #define y second #define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
typedeflonglong LL; typedef pair<int, int> PII;
constint N = 2000010, M = N << 1; // 开两倍空间(点集为两倍) constint INF = 0x3f3f3f3f;
int n, m; int h[N], e[M], ne[M], w[M], idx; int dfn[N], low[N], timestamp; int stk[N], top; bool in_stk[N]; int scc_cnt, id[N];
inlinevoidadd(int a, int b){ e[++ idx] = b, ne[idx] = h[a], h[a] = idx; }
voidtarjan(int ver) { dfn[ver] = low[ver] = ++ timestamp; stk[++ top] = ver, in_stk[ver] = true; for (int i = h[ver]; ~i; i = ne[i]) { int to = e[i]; if (!dfn[to]) { tarjan(to); low[ver] = min(low[ver], low[to]); } elseif (in_stk[to]) low[ver] = min(low[ver], dfn[to]); } if (low[ver] == dfn[ver]) { ++ scc_cnt; int temp; do { temp = stk[top --], in_stk[temp] = false; id[temp] = scc_cnt; } while (temp != ver); } }
signedmain() { // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); memset(h, -1, sizeof h); cin >> n >> m; while (m --) { // 这里都是 a 或 b 的情况,但是变量可以取假的 int a, b, tpa, tpb; cin >> a >> tpa >> b >> tpb; if (tpa && tpb) // a == 1 && b == 1 add(a + n, b), add(b + n, a); elseif (tpa && !tpb) add(a + n, b + n), add(b, a); elseif (!tpa && tpb) add(a, b), add(b + n, a + n); elseadd(a, b + n), add(b, a + n); }
for (int ver = 1; ver <= n << 1; ver ++)// 注意边界 if (!dfn[ver]) tarjan(ver);
for (int ver = 1; ver <= n; ver ++) if (id[ver] == id[ver + n]) returnputs("IMPOSSIBLE"), 0; puts("POSSIBLE"); for (int ver = 1; ver <= n; ver ++) cout << (id[ver] < id[ver + n]) << ' '; cout << '\n';