好好写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的更多相关文章

  1. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

  2. 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 ...

  3. 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 ...

  4. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

  5. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

  6. 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 ...

  7. POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Descr ...

  8. 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 ...

  9. POJ 3678 Katu Puzzle

    Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 ...

随机推荐

  1. DHTML中window的使用

    window对象是对浏览器窗口进行操作的对象.以下列出一些常用的对象(三级为对象的方法.属性) |-navigator:是对浏览器信息进行操作的对象 |-history:包含用户浏览过的url信息 | ...

  2. let块级作用域

    let是es6中新加的作用域,即块级作用域. var申明的变量要么全局,要么函数级,而let允许把变量的作用域限制在块级域中,这里的块级可以是()内,或{}内. 示例: code_1: "u ...

  3. c语言学习笔记.内存管理.

    内存: 每个程序的内存是分区的:堆区.栈区.静态区.代码区. 1.代码区:放置所有的可执行代码,包括main函数. 2.静态区:存放所有的全局变量和静态变量. 3.栈区:栈(stack),先进后出.存 ...

  4. Java的继承和多态

    看了博客园里面的一个文章,关于java的继承和多态: class A ...{ public String show(D obj)...{ return ("A and D"); ...

  5. es6新语法Object.assign()

    1.介绍 Object.assign用于对象的合并,将源对象的所有可枚举属性复制到目标对象,只拷贝源对象自身的属性继承属性补考呗 Object.assign(target,source1,...)第一 ...

  6. django框架<二>

    django框架:   Models 1.基本创建 Django提供了一个抽象层("Model")的构建和管理Web应用程序的数据. Django使用一种新的方式,即:关系对象映射 ...

  7. C++学习之路(九):从菱形继承引入的对象模型

    一.单继承 class A {int a;}; class B : public A {int b;}; 普通的单继承关系,类的大小是由其虚表指针和非静态成员函数大小决定.故上述sizeof(A)的大 ...

  8. linux initcall 介绍 (转自http://blog.csdn.net/fenzhikeji/article/details/6860143)

    现在以module_init为例分析initcall在内核中的调用顺序 在头文件init.h中,有如下定义: #define module_init(x)     __initcall(x); 很明显 ...

  9. Mysql存储之ORM框架SQLAlchemy(一)

    上一篇我们说了mysql存储的原生语句方式,因为原生语句每次写都比较的复杂,所以这里我们说一种引用实体类的方式来操作数据库. 什么是ORM ORM技术:Object-Relational Mappin ...

  10. c# 使用httpclient

    using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using ...