POJ3687 Katu Puzzle
好好写2-sat
如果a1-->b1矛盾则连边a1-->b2和b1-->a2
我定了一个ccnt和cnt变量,结果少打一个c,wa了好多次(lll¬ω¬)
By:大奕哥
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=1e4+;
int top,num,cnt,ccnt,n,m;
int low[N],dfn[N],vis[N],head[N],col[N],s[N];
struct node
{
int to,nex;
}e[];
void add(int x,int y)
{
e[++ccnt].to=y;e[ccnt].nex=head[x];head[x]=ccnt;
}
void dfs(int x)
{
s[++top]=x;dfn[x]=low[x]=++cnt;vis[x]=;
for(int i=head[x];i;i=e[i].nex)
{
int y=e[i].to;
if(!dfn[y])
{
dfs(y);
low[x]=min(low[x],low[y]);
}
else if(vis[y])
low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x])
{
++num;
while(s[top+]!=x)
{
int a=s[top--];
vis[a]=;
col[a]=num;
}
}
}
bool solve()
{
for(int i=;i<=n*;++i)
{
if(!dfn[i])dfs(i);
}
for(int i=;i<=n;++i)if(col[i]==col[i+n])return ;
return ;
}
void init()
{
top=num=cnt=ccnt=;
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(head,,sizeof(head));
memset(vis,,sizeof(vis));
memset(col,,sizeof(col));
}
int main()
{
while(~ scanf("%d%d",&n,&m))
{
init();int a,b,c;char s[];
for(int i=;i<=m;++i)
{//x 0 x+n 1
scanf("%d%d%d%s",&a,&b,&c,s);a++;b++;
if(s[]=='A')
{
if(c==)
{
add(a+n,b+n);add(b,a);//1 0
add(a,b);add(b+n,a+n);// 0 1
add(a,b+n);add(b,a+n);// 0 0
}
else
{
add(a+n,b);add(b+n,a);//1 1
}
}
else if(s[]=='X')
{
if(c==)
{
add(a+n,b);add(b+n,a);//1 1
add(a,b+n);add(b,a+n);// 0 0
}
else
{
add(a,b);add(b+n,a+n);// 0 1
add(a+n,b+n);add(b,a);// 1 0
}
}
else
{
if(c==)
{
add(a,b+n);add(b,a+n);//0 0
}
else
{
add(a+n,b);add(b+n,a);// 1 1
add(a+n,b+n);add(b,a);// 1 0
add(a,b);add(b+n,a+n);// 0 1
}
}
}
if(solve())puts("YES");
else puts("NO");
}
}
POJ3687 Katu Puzzle的更多相关文章
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- poj 3678 Katu Puzzle(2-sat)
Description Katu Puzzle ≤ c ≤ ). One Katu ≤ Xi ≤ ) such that for each edge e(a, b) labeled by op and ...
- POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- POJ 3678 Katu Puzzle (2-SAT)
Katu Puzzle Time Limit: 1000MS ...
- POJ 3678 Katu Puzzle (经典2-Sat)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- poj 3678 Katu Puzzle 2-SAT 建图入门
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9987 Accepted: 3741 Descr ...
- POJ3678 Katu Puzzle 【2-sat】
题目 Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean ...
- POJ 3678 Katu Puzzle
Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 ...
随机推荐
- HDU3681 Prison Break
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- windows下启动mysql服务的命令行启动和手动启动方法
1.图形界面下启动mysql服务. 在图形界面下启动mysql服务的步骤如下: (1)打开控制面板->管理工具->服务,如下图所示: 可以看到Mysql服务目前的状态是未启动(未写已启动的 ...
- CodeForces - 1016B
You are given two strings ss and tt, both consisting only of lowercase Latin letters. The substring ...
- HDU 1045 Fire Net (深搜)
题目链接 Problem DescriptionSuppose that we have a square city with straight streets. A map of a city is ...
- koa源码阅读[2]-koa-router
koa源码阅读[2]-koa-router 第三篇,有关koa生态中比较重要的一个中间件:koa-router 第一篇:koa源码阅读-0第二篇:koa源码阅读-1-koa与koa-compose k ...
- NASA: A Closer View of the Moon(近距离观察月球)
Posted to Twitter by @Astro_Alex, European Space Agency astronaut Alexander Gerst, this image shows ...
- JS几个常用的工具函数
一个项目中JS也不可避免会出现重用,所以可以像Java一样抽成工具类,下面总结了几个常用的函数: 1.日期处理函数 将日期返回按指定格式处理过的字符串: function Format(now,mas ...
- Linux端口占用
1.netstat netstat -anp | grep 23232 Sample: [root@BICServer 0825]# netstat -anp | grep 23232 tcp 0 0 ...
- 轻量级运维工具-pssh,pscp,prsync,pslurp,pnuke
批量执行,并行传输,远程killall #yum安装 yum install pssh -y #yun安装后pscp改名为pscp.pssh #源码编译 wget https://pypi.pytho ...
- php判断是手机还是pc访问从而走不同url
<?php header("Content-type:text/html;charset=utf-8"); function is_mobile(){ $user_agent ...