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\) . 首先来看 ...
随机推荐
- LintCode 539: Move Zeroes
终于下决心开始刷题了! 选择LintCode而不是LeetCode主要是因为LintCode操作更顺手,希望能够坚持下去. 还是循序渐进吧,数据结构和算法的东西很久没碰都很生疏了,先找找感觉. 这是一 ...
- 在Unity中实现屏幕空间阴影(1)
接着上篇文章,我们实现了SSR效果. 其中的在屏幕空间进行光线追踪的方法是通用的.借此我们再实现一种屏幕空间的效果,即屏幕空间阴影. 文中的图片来自Catlike coding http://catl ...
- centos6.5 导入matplotlib报错 No module named '_tkinter
1.解决方案 在centos系统下,导入matplotlib时,出现ImportError: No module named ‘_tkinter’的错误,首先 yum list installed | ...
- Redis数据类型之散列(hash)
1. 什么是散列 散列类似于一个字典,是一个<K, V>对的集合,不过这个key和value都只能是字符串类型的,不能嵌套,可以看做Java中的Map<String, String& ...
- VC调用易语言DLL
易语言方面: .版本 .子程序 show, , 公开 ' 本名称子程序用作测试程序用,仅在开发及调试环境中有效,编译发布程序前将被系统自动清空,请将所有用作测试的临时代码放在本子程序中. ***注意不 ...
- perl6正则 6: 大小写/空白/匹配所有符合
这个 :g 只能写在外面 m:g /re/
- 516.Longest Palindromic subsequence---dp
题目链接:https://leetcode.com/problems/longest-palindromic-subsequence/description/ 题目大意:找出最长回文子序列(不连续), ...
- 使用正则表达式匹配IP地址
IP地址分为4段,以点号分隔.要对IP地址进行匹配,首先要对其进行分析,分成如下部分,分别进行匹配: 第一步:地址分析,正则初判 1.0-9 \d 进行匹配 2.10-99 [1-9]\d 进行匹 ...
- sendEmail实现邮件报警
安装 wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz 或者点击下载 tar -xf sen ...
- leetcode 168. Excel Sheet Column Title 171 Excel Sheet Column Number
题目 //像10进制一样进行 转换 只是要从0开始记录 class Solution { public: string convertToTitle(int n) { char a; string ...