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\) . 首先来看 ...
随机推荐
- 简单高效的asp.net目录树源代码
前台页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default. ...
- 面试整理(1):原生ajax
接到电话面试,有一些送分题答的不好,在这里整理一下 问题:原生ajax的工作流程是怎么样的? 老用封装好的工具,原生的ajax其实并不熟悉,今天复习一下.主要参考http://www.w3school ...
- 【leetcode 简单】第二十题 合并两个有序数组
给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m 和 n. ...
- Network POJ - 3694 (LCA+tarjan+桥)
题目链接:https://vjudge.net/problem/POJ-3694 具体思路:首先可以通过缩点的方式将整个图变成一个树,并且树的每条边是桥,但是我们可以利用dfn数组将整个图变成树,这样 ...
- VueJS 集成 medium editor 自定义编辑器按钮
详见我的新博客: 守望之吻
- document.write 简介
document.write 的执行分两种情况: 第一种:dom加载已完成 1. 执行 document.open() (即会清空document) 2. 执行 document.write() 3. ...
- django【ORM】model字段类型
1.AutoField 一个自增的IntegerField,一般不直接使用,Django会自动给每张表添加一个自增的primary key. 2.BigIntegerField 64位整数, -922 ...
- 【bzoj5050】【bzoj九月月赛H】建造摩天楼
讲个笑话,这个题很休闲的. 大概是这样的,昨天看到这个题,第一眼星际把题目看反了然后感觉这是个傻逼题. 后来发现不对,这个修改一次的影响是很多的,可能导致一个数突然可以被改,也可能导致一个数不能被改. ...
- 《深入理解Java虚拟机》笔记--第十三章、线程安全与锁优化
先保证并发的正确性,然后在此基础上来实现高效. 线程安全: 当多个线程访问一个对象时,如果不考虑这些线程在运行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方进行任何其他的协调操 ...
- vmware linux虚拟机连接ip设置
首先: 点击VMware 编辑->虚拟网络编辑器: 然后选中VMnet8的查看NAT设置: 上图第二步(记下红框中网关地址和子网掩码): 第三步(用于设置虚拟机地址范围): 接下来就是设置虚拟机 ...