当前位置: 首页 > news >正文

2-sat板子

vector<int>e[maxn];
int n,m;
int inscc[maxn];
int low[maxn],dfn[maxn];
stack<int>stk;
int instk[maxn];
int tot,cnt;
vector<int>scc[maxn];void dfs(int u,int fa){low[u]=dfn[u]=++tot;stk.push(u);instk[u]=1;for(int v:e[u]){if(!dfn[v]){//树边dfs(v,u);low[u] =min(low[u],low[v]);}else if(instk[v]){//非树边low[u] = min(low[u],dfn[v]);}}if(dfn[u]==low[u]){++cnt;//处理非根节点while(stk.top()!=u){scc[cnt].pb(stk.top());inscc[stk.top()]=cnt;instk[stk.top()]=0;stk.pop();}//处理根节点scc[cnt].pb(stk.top());inscc[stk.top()]=cnt;instk[stk.top()]=0;stk.pop();}
}
void solve(){cin>>n>>m;rep(i,1,m){int idx,a,jdx,b;cin>>idx>>a>>jdx>>b;int x=idx,y=jdx;int nota= (a^1),notb =(b^1);e[x+nota*n].pb(y+b*n);e[y+notb*n].pb(x+a*n);}for(int i=1;i<=2*n;i++){if(inscc[i])continue;dfs(i,0);}for(int i=1;i<=n;i++){if(inscc[i]==inscc[i+n]){cout<<"IMPOSSIBLE"<<endl;return;}}cout<<"POSSIBLE"<<endl;for(int i=1;i<=n;i++){if(inscc[i]>inscc[i+n]){cout<<1<<' ';}else cout<<0<<' ';}cout<<endl;
}
http://www.gsyq.cn/news/7427.html

相关文章:

  • Node.js 中使用 .env 文件管理环境变量
  • pythonjs逆向 破解滑动验证码 - hello-*
  • Bun:不仅是新的JavaScript运行时,并且重塑了JavaScript工具链
  • AI Agent 与 MCP 核心解析与企业级应用指南
  • P3934 [Ynoi Easy Round 2016] 炸脖龙 I 做题记录
  • 正确输入连字号、连接号、破折号和负号
  • python基础-元组
  • python基础篇-list(列表)
  • vscode使用powershell中文乱码
  • Untitled
  • 完整教程:论园区电气安全管理系统的重要性
  • 没搞懂的package.json
  • 你应该考虑放弃 react-router 的数据路由模式,改而使用更加适合国内版本的封装版本(包含完整可 CV 的模版)
  • 基于CSU8RP1186芯片的握力器解决方案
  • 深入解析:C++ 内存管理:从底层原理到实战应用
  • sass踩坑:@import导致前端项目打包体积膨胀
  • 深入解析:Java 设计模式之桥接模式(Bridge Pattern)
  • 【AP出版】第四届数理统计与经济分析国际学术会议 (MSEA 2025)
  • 数据结构 Trick 之:区间子区间计数
  • mapstruct.Mapper|Mapping详解
  • XXL-JOB(3)
  • web17(备份的sql文件泄露)
  • web11(通过Dns检查查询Flag)
  • 立创商城
  • ctfshow web 10
  • KEITHLEY 数字万用表
  • 大数据毕业设计选题推荐-基于大数据的慢性肾病数据可视化分析系统-Spark-Hadoop-Bigdata - 详解
  • get请求图片文件转为base64编码
  • BMS与威纶通人机界面通信问题
  • CodeGPT AI代码狂潮来袭!个人完全免费使用谷歌Gemini大模型 超越DeepSeek几乎是地表最强