1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| #include <stdio.h> #include <string.h> #include <iostream> #include <stack> using namespace std;
const int N = 2e6 + 10;
struct node { int u, v, next; node() {} node(int _u, int _v, int _next): u(_u), v(_v), next(_next) {} } e[N]; int h[N], tot = 0; void add(int u, int v) { e[++tot] = node(u, v, h[u]); h[u] = tot; }
int dfn[N], low[N], tag = 0; int id[N], num = 0;
stack<int> s;
int n, m;
void tarjan(int u) { dfn[u] = low[u] = ++tag; s.push(u); for(int i = h[u]; i; i = e[i].next) { int v = e[i].v; if(dfn[v]) { if(!id[v]) low[u] = min(low[u], dfn[v]); } else { tarjan(v); low[u] = min(low[u], low[v]); } } if(dfn[u] == low[u]) { id[u] = ++num; for(; s.top() != u; s.pop()) id[s.top()] = num; s.pop(); } }
int main() { freopen("p4782.in", "r", stdin); scanf("%d%d", &n, &m); for(int i=1, _i, a, _j, b, u, v; i<=m; ++i) { scanf("%d%d%d%d", &_i, &a, &_j, &b); u = (_i-1)*2 + a, v = (_j-1)*2 + b; add(u^1, v); add(v^1, u); } for(int i=0; i<(n<<1); ++i) if(!dfn[i]) tarjan(i); for(int i=0; i<(n<<1); i+=2) { if(id[i] == id[i^1]) { printf("IMPOSSIBLE\n"); return 0; } } printf("POSSIBLE\n"); for(int i=0; i<(n<<1); i+=2) printf("%d ", id[i] < id[i^1] ? 0 : 1); return 0; }
|