#include<iostream>#include<stack>#include<queue>usingnamespace std;constint maxn =2e6+10;structEdge{int nxt, to;}edges[maxn];bool vis[maxn];int tot;int id;int cols;int in[maxn];int col[maxn];int dfn[maxn];int low[maxn];int head[maxn];
stack <int> stk;inlinevoidadd(int u,int v){
tot++;
edges[tot].nxt = head[u];
edges[tot].to = v;
head[u]= tot;}voidtar(int x){
dfn[x]= low[x]=++id;
stk.push(x);
vis[x]=true;for(int i = head[x]; i; i = edges[i].nxt){int to = edges[i].to;if(!dfn[to]){tar(to);
low[x]=min(low[x], low[to]);}elseif(vis[to]){
low[x]=min(low[x], dfn[to]);}}if(dfn[x]== low[x]){
cols++;int y;do{
y = stk.top();
stk.pop();
col[y]= cols;
vis[y]=false;}while(x != y);}}intmain(){int n, m;
cin >> n >> m;for(int i =1; i <= m;++i){int x, a, y, b;
cin >> x >> a >> y >> b;if(a ==true&& b ==true){add(x, y + n);add(y, x + n);}if(a ==false&& b ==false){add(x + n, y);add(y + n, x);}if(a ==true&& b ==false){add(x, y);add(y + n, x + n);}if(a ==false&& b ==true){add(x + n, y + n);add(y, x);}}for(int i =1; i <=2* n;++i){if(!dfn[i])tar(i);}for(int i =1; i <= n;++i){if(col[i]== col[i + n]){
cout <<"IMPOSSIBLE"<<'\n';return0;}}
cout <<"POSSIBLE"<<'\n';for(int i =1; i <= n;++i){if(col[i]> col[i + n]){
cout <<1<<' ';}else{
cout <<0<<' ';}}return0;}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】