hdu 1824 Let's go home (2-sat)
来源:互联网 发布:js省市区三级联动 编辑:程序博客网 时间:2024/06/03 05:17
# include <stdio.h># include <algorithm># include <string.h># include <stack>using namespace std;# define MAXN 6010# define MAXM 10010struct node{ int to; int next;} edge[MAXM];int tot;int tim,num;int be[MAXN];bool instack[MAXN];int dfn[MAXN],low[MAXN];int head[MAXN];int pos[MAXN];stack<int>s;int n,m;void init(){ tot=0; memset(head,-1,sizeof(head));}void add(int from,int to){ edge[tot].to=to; edge[tot].next=head[from]; head[from]=tot++;}void tarjan(int cur){ dfn[cur]=low[cur]=++tim; s.push(cur); instack[cur]=true; for(int i=head[cur]; i!=-1; i=edge[i].next) { int to=edge[i].to; if(!dfn[to]) { tarjan(to); low[cur]=min(low[cur],low[to]); } else if(instack[to]) { low[cur]=min(low[cur],dfn[to]); } } if(dfn[cur]==low[cur]) { int tem = -1; ++num; while(tem != cur) { tem = s.top(); s.pop(); instack[tem] = false; be[tem] = num; } }}void solve(){ memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(instack,0,sizeof(instack)); memset(be,0,sizeof(be)); while(!s.empty()) s.pop(); tim=num=0; for(int i=0; i<2*n; i++) { if(!dfn[i]) tarjan(i); } bool ans=true; for(int i=0; i<2*n; i++) { if(be[i]==be[i+n]) { ans=false; break; } } if(ans) puts("yes"); else puts("no");}int main(){ int x,y,z; while(~scanf("%d%d",&n,&m)) { init(); for(int i=0; i<n; i++) { scanf("%d%d%d",&x,&y,&z); pos[x]=i; pos[y]=pos[z]=i+n; } for(int i=0; i<m; i++) { scanf("%d%d",&x,&y); if(pos[x]>=n) add(pos[x]-n,pos[y]); else add(pos[x]+n,pos[y]); if(pos[y]>=n) add(pos[y]-n,pos[x]); else add(pos[y]+n,pos[x]); } solve(); } return 0;}
0 0
- HDU 1824 Let's go home 2-sat
- hdu 1824 Let's go home(2-sat入门)
- HDU 1824 Let's go home (2-SAT)
- HDU 1824 Let's go home (2-SAT判断)
- HDU 1824 Let's go home(2-SAT)
- Hdu 1824 Let's go home (2-sat 可行性判定)
- 【HDU】1824 Let's go home 2-sat
- HDU 1824 Let's go home(2-sat)
- HDU 1824 Let's go home (2-SAT)
- HDU - 1824 Let's go home(2-SAT)
- HDU 1824 Let's go home (2-SAT判定)
- HDU 1824 Let's go home 2-sat基础
- hdu 1824 Let's go home (2-sat)
- HDU 1824 Let's go home 2-Sat
- HDU-1824-Let's go home(2-SAT)
- HDU 1824 Let's go home(2-SAT)
- HDU 1824 Let's go home(2-SAT)
- hdu 1824 Let's go home(s-sat)
- centos6.3(64位) 安装apr
- PostgreSQL xlog $PGDATA and zfs snapshot based central backup & PITR case
- Ubuntu15.04中测试安装的opencv2.4.9 时遇到usr/bin/ld: cannot find -lcufft解决方法。
- 2.Xamarin.Forms里的文本控制
- UFT对象库的使用
- hdu 1824 Let's go home (2-sat)
- C++文件操作
- 马士兵Java课堂笔记-3-Switch循环语句小细节
- recovery test script for zfs snapshot clone + postgresql stream replication + archive
- 影像去条带
- 整理IOS9适配
- CASE : zfs snapshot backup for PostgreSQL when use multi-zfs filesystem
- 黑马程序员——Java基础----IO(File类、Properties类、打印流、序列流、合并流)(3)
- DDL,DML