题目链接

题意

给定一张图,对于每条边给出一个运算符\((\&,|,\otimes)\)和一个值\(c(0 \le c \le 1)\)。问能否通过给每个点赋上一个值。使得每条边通过指定的运算都能得到指定的值。

思路

\(2-sat\)问题,需要注意的是当两数\(\&\)起来为\(1\)时。必须全部为\(1\),所以就从每个点的\(0\)向\(1\)连边。同理,当两数\(|\)起来为\(0\)时,必须全部为\(0\),所以就从每个点的\(1\)向\(0\)连边。

代码

/*
* @Author: wxyww
* @Date: 2019-04-27 16:42:24
* @Last Modified time: 2019-04-27 17:09:58
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 3000 + 10,M = 5000000 + 100;
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
struct node {
int v,nxt;
}e[M];
int head[N],ejs;
void add(int u,int v) {
e[++ejs].v = v;e[ejs].nxt = head[u];head[u] = ejs;
}
char s[5];
int sta[N],dfn[N],top,coljs,cnt,vis[N],low[N],col[N];
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
sta[++top] = u;
vis[u] = 1;
for(int i = head[u];i;i = e[i].nxt) {
int v = e[i].v;
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(vis[v]) low[u] = min(low[u],low[v]);
}
if(low[u] == dfn[u]) {
++coljs;
do {
int x = sta[top--];
col[x] = coljs;
vis[x] = 0;
}while(sta[top + 1] != u);
}
}
int main() {
int n = read(),m = read();
for(int i = 1;i <= m;++i) {
int u = read() + 1,v = read() + 1,w = read();
scanf("%s",s + 1);
if(s[1] == 'O') {
if(w) add(u,v + n),add(v,u + n);
else add(u + n,u),add(v + n,v);
}
else if(s[1] == 'X') {
if(w) add(u,v + n),add(u + n,v),add(v + n,u),add(v,u + n);
else add(u,v),add(u + n,v + n),add(v,u),add(v + n,u + n);
}
else {
if(w) add(u,u + n),add(v,v + n);
else add(u + n,v),add(v + n,u);
}
}
for(int i = 1;i <= n + n;++i) if(!dfn[i]) tarjan(i);
for(int i = 1;i <= n;++i) {
if(col[i] == col[i + n]) {
puts("NO");return 0;
}
}
puts("YES");
return 0;
}

bzoj3678 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. JavaScript中的typeof

    js中的 typeof 操作符返回一个字符串,表示未经计算的操作数的类型. 其中null.字符串对象.数字对象.布尔对象.日期.数组.正则返回结果都为object,可见typeof返回结果并不精确 测 ...

  2. 虚拟机安装CentOS7(一)

    软件环境 虚拟机:VMware Workstation Linux:CentOS-7-x86_64-DVD-1708.iso镜像文件 虚拟机所在电脑系统:win7 安装步骤 安装VMware 下载Li ...

  3. Android 报错:error: too many padding sections on bottom border

    一.发生错误 [我以为我做了一张完美的.9图片,没想到.9图片还需要画左边和上边,尴尬···] 二.解决方法 .9图片造成错误 [具体内容] 最后修改.9图为

  4. 【English】五、颜色相关

    一.常见颜色 黑色    black    白色    white    蓝色    blue    橙色    orange    黄色    yellow        灰色    gray   ...

  5. [20190418]exclusive latch spin count.txt

    [20190418]exclusive latch spin count.txt--//昨天测试"process allocation" latch,主要这个latch与其它拴锁s ...

  6. c++11の泛型算法

    一.泛型算法泛型算法这个概念是针对容器操作的,我们知道,c++11的顺序容器有vector,list,deque等,对于这些容器,c++11并没给出相应的增删改查方法,而是定义了一组泛型算法 一般的泛 ...

  7. springboot 实现配置文件给常量赋值

    @Component @ConfigurationProperties(prefix = "task.cron") public class TaskCronParam imple ...

  8. sprintboot 中占位符及多环境配置

    (原) 关于springboot中多环境配置问题 1.在application.properties文件中通过 spring.profiles.active=... 选择系统所要加载的配置文件,这里的 ...

  9. Linux SHELL中sh和bash的区别

    什么是SHELL? shell的中文意思就是贝壳,其实比较类似于我们内核的壳.简而言之就是只要能够操作应用程序的接口都能够称为SHELL.狭义的shell指的是命令行方面的软件,广义的SHELL则包括 ...

  10. UltraEdit文本行数多变一和一边多

    一.UltraEdit文本行数多行转换成一行 1.文本样式内容 1.qwertyuuiopqwertyuuiopqwertyuuiopqwertyuuiopqwertyuuiopqwertyuuiop ...