2-SAT,拆成六个点。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std; const int maxn=+; int T,N,M;
stack<int>S;
vector<int>G[maxn];
vector<int>FG[maxn];
int Belong[maxn];
int flag[maxn];
int Block; int X[maxn]; void init()
{
for(int i=; i<maxn; i++) G[i].clear();
for(int i=; i<maxn; i++) FG[i].clear();
memset(Belong,,sizeof Belong);
memset(flag,,sizeof flag);
while(!S.empty()) S.pop();
Block=;
} void addEdge(int x,int y)
{
G[x].push_back(y);
FG[y].push_back(x);
} void dfs1(int now)
{
flag[now]=;
for(int i=; i<G[now].size(); i++)
if(!flag[G[now][i]])
dfs1(G[now][i]);
S.push(now);
} void dfs2(int now)
{
Belong[now]=Block;
for(int i=; i<FG[now].size(); i++)
if(!Belong[FG[now][i]])
dfs2(FG[now][i]);
} bool judge()
{
for(int i=; i<*N; i++) if(!flag[i]) dfs1(i);
while(!S.empty())
{
int Top=S.top();
S.pop();
if(!Belong[Top])
{
Block++;
dfs2(Top);
}
}
for(int i=; i<*N; i++)
if(Belong[i]==Belong[i+*N])
return ;
return ;
} void read()
{
int A,B,C;
for(int i=;i<N;i++)
{
addEdge(*i+,*i++*N);
addEdge(*i+,*i++*N); addEdge(*i+,*i++*N);
addEdge(*i+,*i++*N); addEdge(*i+,*i++*N);
addEdge(*i+,*i++*N);
}
for(int i=;i<N;i++)
{
scanf("%d",&X[i]); X[i]--;
if(X[i]==)
{
addEdge(*i++*N,*i+);
addEdge(*i++*N,*i+);
}
else if(X[i]==)
{
addEdge(*i++*N,*i+);
addEdge(*i++*N,*i+);
}
else if(X[i]==)
{
addEdge(*i++*N,*i+);
addEdge(*i++*N,*i+);
}
}
for(int i=;i<=M;i++)
{
scanf("%d%d%d",&A,&B,&C);
A--,B--;
if(C==)
{
addEdge(*A+,*B+);
addEdge(*A+,*B+);
addEdge(*A+,*B+); addEdge(*B+,*A+);
addEdge(*B+,*A+);
addEdge(*B+,*A+);
} else if(C==)
{
addEdge(*A+,*B++*N);
addEdge(*A+,*B++*N);
addEdge(*A+,*B++*N); addEdge(*B+,*A++*N);
addEdge(*B+,*A++*N);
addEdge(*B+,*A++*N);
}
}
} int main()
{
scanf("%d",&T);
for(int Case=;Case<=T;Case++)
{
scanf("%d%d",&N,&M);
init();
read();
printf("Case #%d: ",Case);
if(judge()) printf("yes\n");
else printf("no\n");
}
return ;
}

HDU 4115 Eliminate the Conflict的更多相关文章

  1. HDU 4115 Eliminate the Conflict(2-sat)

    HDU 4115 Eliminate the Conflict pid=4115">题目链接 题意:Alice和Bob这对狗男女在玩剪刀石头布.已知Bob每轮要出什么,然后Bob给Al ...

  2. hdu 4115 Eliminate the Conflict ( 2-sat )

    Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. HDU 4115 Eliminate the Conflict(2-SAT)(2011 Asia ChengDu Regional Contest)

    Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...

  4. 图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict

    Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...

  5. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  6. hdu4115 Eliminate the Conflict

    Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

  7. Eliminate the Conflict HDU - 4115(2-sat 建图 hhh)

    题意: 石头剪刀布 分别为1.2.3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一 ...

  8. HDU-4115 Eliminate the Conflict 2sat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115 题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Al ...

  9. HDU 4041 Eliminate Witches! --模拟

    题意: 给一个字符串,表示一颗树,要求你把它整理出来,节点从1开始编号,还要输出树边. 解法: 模拟即可.因为由括号,所以可以递归地求,用map存对应关系,np存ind->name的映射,每进入 ...

随机推荐

  1. js函数大全(2)

    原文地址:http://phperbar.blog.163.com/blog/static/162596182201032935815391/ 1.常规函数 javascript常规函数包括以下9个函 ...

  2. ios中的关键词@property @synthesize

    @interface Person : NSObject{    int myNumber;} @property(nonatomic) int myNumber;//这个关键字是可以带套get 与s ...

  3. 【我与一道水题的抗争之路】 哈理工2323 Emirp(反素数)

    题目: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2323 1,打表的姿势不对. ...

  4. hr定位

    css里写 <style> hr{ position:relative; top: 500px; } </style> 重要!!! hr不能绝对定位, 只能相对定位,所以 hr ...

  5. linux下如何开放80端口

    linux清屏命令:clear linux版本:CentOS6.5 1.开启80端口命令:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT2.保存 ...

  6. Qt之中文显示(QMessageBox、QLineEdit右键菜单等)

    来源:http://blog.sina.com.cn/s/blog_a6fb6cc90101art3.html 在编写Qt程序的时候,总会碰到中文问题,一直都很困惑,原本在使用QLineEdit的时候 ...

  7. Industry Engineer

    IE:有两种,一种是系统方面的,对全厂的物流设计,依据产量做人力估算,机台,设备,手工具的估算等,一种是配合产能提升做制造的改善,以及SOP(Standard Operation Procedure: ...

  8. 静默方式安装window oracle

    1. setup.exe -silent -responseFile "C:\app\software\WIN64_11204\RSP\db_install_window.rsp" ...

  9. Dreamweaver使用过程的小技巧

    在用Dreamweaver中制作网站的过程中,经常会遇到这样的问题,我们要修改一些属性类的标签,如<a href="abc/def.html">,如果我们要把href= ...

  10. XAMPP(v1.83)中的PHP(v5.5.15)访问SQLServer2014

    驱动安装: 1. 下载SQLServer的微软官方PHP驱动,http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx 2. 安装SQLSRV31 ...