bzoj3678 Katu Puzzle
题意
给定一张图,对于每条边给出一个运算符\((\&,|,\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的更多相关文章
- 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\) . 首先来看 ...
随机推荐
- Jetty 开发指南:嵌入式开发示例
Jetty具有嵌入各种应用程序的丰富历史. 在本节中,我们将向您介绍我们的git存储库中的embedded-jetty-examples项目下的一些简单示例. 重要:生成此文档时,将直接从我们的git ...
- 华为7.0系统最简单激活xposed框架的流程
对于喜欢搞机的哥们而言,很多时候会接触到Xposed框架及其种类繁多功能无敌的模块,对于5.0以下的系统版本,只要手机能获得root权限,安装和激活Xposed框架是异常简易的,但随着系统版本的不断更 ...
- Android Studio教程09-加载器Loader的使用
目录 1.加载器特征 2. Loader API 3. 在应用中使用Loader 3.1. 启动加载器 3.2. 重启加载器 3.3. 使用LoaderManager回调 4. 实例: 访问用户联系人 ...
- Linux(CentOS 7)安装测试mysql5.6服务
1.rpm -qa | grep mysql,查看原系统中是否有已经安装得mysql. 注:centos7系统在安装完成后,未安装mysql任何版本. 2. rpm -e --nodeps mysql ...
- 二进制安装 mariadb
默认路径安装MySQL,Mariadb 非常简单,解压,配置权限,修改配置文件基本即可使用:自定义安装稍微有点麻烦,需要修改的地方稍微多点: 下面详细介绍自定义目录,二进制安装mariadb, 使用传 ...
- c#面试题汇总(1)
c#面试题汇总 From: https://www.cnblogs.com/suzhiyong1988/p/5069385.html 下面的参考解答只是帮助大家理解,不用背,面试题.笔试题千变万化 ...
- js得到规范的时间格式函数,并调用
1.js得到规范的时间格式函数 Date.prototype.format = function(fmt) { var o = { "M+" : this.getMonth()+1 ...
- SpringBoot Mybatis 使用LocalDateTime
mybatis-spring-boot-starter 2.0.1 会报错,不知道如何解决(建议先不用) mybatis-spring-boot-starter 2.0.1 - 1.3.2 版本不会报 ...
- Video clip 视频剪辑:入门级
作为一个对小说漫画电视剧电影的设计有着自己独特需求的人,一直对视频剪辑有着浓厚的兴趣,之前用爱剪辑这种通俗易上手的软件做过简单的小视频.但是这个毕竟满足不了我自己的需求而且属于完全门外汉级别.这次终于 ...
- [idea] SpringBoot整合swagger2实现CRUD
一:创建SpringBoot ,在pom.xml文件中加入jar包 <dependency> <groupId>io.springfox</groupId> < ...