当前位置: 首页 > 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.hskmm.com/?act=detail&tid=8567

相关文章:

  • centos 7中安装jenkins
  • pythonjs逆向 破解滑动验证码 - hello-*
  • 解决 pandas.to_csv 乱码、丢失行和自动换行问题 时间转换
  • JavaDay7
  • 前端场景题笔记
  • P3934 [Ynoi Easy Round 2016] 炸脖龙 I 做题记录
  • 【CompletableFuture 核心操作全解】详细注释版
  • 关于学术不端的一些思考
  • python基础-字典
  • pod 内nslookup请求时常异常
  • 单调队列优化DP
  • 4.5.11版本闪亮登场~快来看看有哪些新功能
  • 教你数分钟内创建并运行一个 DolphinScheduler Workflow!
  • AT_agc065_b [AGC065B] Erase and Insert
  • 《大模型时代——智能体的崛起与应用实践(微课视频版)》
  • 第三节:GoLangChain提示词(Prompts)处理详解
  • rhel8 中vdo 邏輯卷的邏輯擴容
  • Codeforces Round 1051 (Div. 2) 部分题解
  • kingbase金仓数据库的密码有效期和密码复杂度
  • HDF5文件
  • Error encountered when performing Introspect the Portion of idea Introspect using JDBC metadata在哪设置
  • 核桃 CSP-S 模拟
  • 正确输入连字号、连接号、破折号和负号
  • 9 月记录
  • python基础-元组
  • .net core中获得程序集以及注入框架的方法总结
  • python基础篇-list(列表)
  • vscode使用powershell中文乱码
  • 关于如何读懂 P11832 [省选联考 2025] 图排列?
  • Untitled