好好写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. 在ASP.NET中备份和还原数据库

        昨天看了<C#项目实录>中的进销存管理系统,和其他书里讲的案例一样,无非也就是数据库增删查改,但是这个进销存系统中有一个备份和还原数据库的功能,蛮有兴趣的,看了一下代码,原来如此, ...

  2. python初步学习-python模块之 logging

    logging 许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在python中,我们不需要第三方的日志组件,python为我们提供了简单易用.且 ...

  3. vc6列表框多选时,获取哪些项被选中

    //vc6列表框多选时,获取哪些项被选中...... void CWebcyzDlg::OnButton2() { int n = m_mylist1.GetSelCount();//首先获取一共有多 ...

  4. Python作业选课系统(第六周)

    作业需求: 角色:学校.学员.课程.讲师.完成下面的要求 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 ...

  5. 福建工程学院寒假作业第一周G题

    涨姿势题1 TimeLimit:1000MS  MemoryLimit:128000KB 64-bit integer IO format:%lld   涨姿势题就是所谓的优化题,在组队赛中,队伍发现 ...

  6. Perl6多线程3: Promise start / in / await

    创建一个Promise 并自动运行: my $p = Promise.start({say 'Hello, Promise!'}); 如果把代码改成如下, 我们会发现什么也没打印: ;say 'Hel ...

  7. thinkphp中的验证器

  8. python进阶之内置函数和语法糖触发魔法方法

    前言 前面已经总结了关键字.运算符与魔法方法的对应关系,下面总结python内置函数对应的魔法方法. 魔法方法 数学计算 abs(args):返回绝对值,调用__abs__; round(args): ...

  9. [Leetcode] Longest Palindromic Subsequence

    Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...

  10. dm368 ipnc3.0环境搭建脚本

    前言 为了方便其他人搭建dm368 ipnc3.0环境,我写了个脚本,执行脚本就可以自动搭建好环境了,绝对的傻瓜操作了,不过有一个地方让我很郁闷,那就是在用sed替换掉某段内容的时候(143行--15 ...