hdu3062 Party 2-sat 基础题
来源:互联网 发布:明星主播用的软件 编辑:程序博客网 时间:2024/05/17 06:10
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3062
n个元组,每个元组只能出一个元素,其中一些人有矛盾,不能同时出,判断是否能出齐n个人
一篇很不错的ppt《由
#include<cstdio>#include<vector>#include<stack>#include<cstring>#define Min(a,b) a<b?a:busing namespace std;const int maxn = 1010*2;vector<int> g[maxn];stack<int> st;int low[maxn],dfn[maxn],instack[maxn],scc[maxn];int time,sccn;void tarjin(int u){low[u]=dfn[u]=++time;st.push(u);instack[u]=1;for(int i=0;i<g[u].size();i++){int v = g[u][i];if(!dfn[v]){tarjin(v);low[u]=Min(low[u],low[v]);}else if(instack[v])low[u]=Min(low[u],dfn[v]);}if(low[u]==dfn[u]){sccn++;int x;do{x = st.top();st.pop();instack[x]=0;scc[x]=sccn;}while(x!=u);}}int main(){int n,m,flag;while(scanf("%d%d",&n,&m)!=EOF){int a1,a2,c1,c2;for(int i=0;i<2*n;i++)g[i].clear();for(int i=0;i<m;i++){scanf("%d%d%d%d",&a1,&a2,&c1,&c2);//0 1int u = a1*2+c1;//1int v = a2*2+c2;//3int u1 = a1*2+!c1;//0int v2 = a2*2+!c2;//2g[v].push_back(u1);g[u].push_back(v2);}time=sccn=flag=0;memset(dfn,0,sizeof(dfn));memset(low,0,sizeof(low));memset(instack,0,sizeof(instack));memset(scc,0,sizeof(scc));while(!st.empty())st.pop();for(int i=0;i<2*n;i++)//求强连通分量 {if(!dfn[i])tarjin(i);}for(int i=0;i<n;i++)//判断一个元组的两个元素是否在同一个强连通分量里 {if(scc[2*i]==scc[2*i+1]){flag=1;break;}}if(flag)printf("NO\n");else printf("YES\n");}}
0 0
- hdu3062 Party 2-sat 基础题
- 【hdu3062】【2-sat】Party
- HDU3062-Party(2-SAT)
- 2SAT hdu3062 Party
- HDU3062 Party (2-sat)
- [2-sat][裸题] HDU3062 Party
- hdu3062 Party(2-SAT入门)
- hdu3062 Party--强连通 & 2-sat & 判断可行性
- hdu3062 2-SAT
- hdu3062 2-sat
- hdu3062 2-sat
- hdu3062 Party
- 2-SAT 入门题 party
- HDU 3062 Party 2-SAT 入门题
- HDU 3062 Party(2-SAT简单题)
- HDU 3062 Party(2-SAT简单题)
- HDU 3062 Party. (2-SAT简单题)
- tarjan 2-sat: party
- 线程安全与可重入
- linux安装1.8jdk
- 单链表 初始化 创建 头插法 尾插法 插入 删除 查找 合并 长度
- ANSYS学习1--概述
- js事件监听机制(事件捕获)总结
- hdu3062 Party 2-sat 基础题
- ADB(android debug bridge)常见命令
- Android应用瘦身,从18MB到12.5MB
- Scrapy 1.3.2
- nginx-初探
- Objective-C 运行时编程指南 之 Interacting with the Runtime
- Graph Valid Tree
- git建立本地仓库、gitHub上传项目以及git和gitHub的关系
- vlan间的路由(二)