POJ3678 Katu Puzzle
原题链接
\(2-SAT\)模板题。
将\(AND,OR,XOR\)转换成\(2-SAT\)的命题形式连边,用\(tarjan\)求强连通分量并检验即可。
#include<cstdio>
using namespace std;
const int N = 2010;
const int M = 4e6 + 10;
int fi[N], di[M], ne[M], dfn[N], low[N], st[N], bl[N], l, tp, ti, SCC;
bool v[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline int re_l()
{
char c = getchar();
for (; c < 'A' || c > 'Z'; c = getchar());
return !(c ^ 'A') ? 1 : (c ^ 'O' ? 2 : 0);
}
inline void add(int x, int y)
{
di[++l] = y;
ne[l] = fi[x];
fi[x] = l;
}
inline int minn(int x, int y)
{
return x < y ? x : y;
}
void tarjan(int x)
{
int i, y;
dfn[x] = low[x] = ++ti;
st[++tp] = x;
v[x] = 1;
for (i = fi[x]; i; i = ne[i])
{
y = di[i];
if (!dfn[y])
{
tarjan(y);
low[x] = minn(low[x], low[y]);
}
else
if (v[y])
low[x] = minn(low[x], dfn[y]);
}
if (!(low[x] ^ dfn[x]))
{
++SCC;
do
{
y = st[tp--];
v[y] = 0;
bl[y] = SCC;
} while (x ^ y);
}
}
int main()
{
int i, n, m, x, y, z, p;
n = re();
m = re();
for (i = 1; i <= m; i++)
{
x = re() + 1;
y = re() + 1;
z = re();
p = re_l();
if (!p)
{
if (z)
{
add(x, y + n);
add(y, x + n);
}
else
{
add(x + n, x);
add(y + n, y);
}
}
else
if (!(p ^ 1))
{
if (z)
{
add(x, x + n);
add(y, y + n);
}
else
{
add(x + n, y);
add(y + n, x);
}
}
else
{
if (z)
{
add(x, y + n);
add(y, x + n);
add(x + n, y);
add(y + n, x);
}
else
{
add(x, y);
add(y, x);
add(x + n, y + n);
add(y + n, x + n);
}
}
}
for (i = 1; i <= (n << 1); i++)
if (!dfn[i])
tarjan(i);
for (i = 1; i <= n; i++)
if (!(bl[i] ^ bl[i + n]))
{
printf("NO");
return 0;
}
printf("YES");
return 0;
}
POJ3678 Katu Puzzle的更多相关文章
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 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 2sat
题目链接:http://poj.org/problem?id=3678 分别对and,or,xor推出相对应的逻辑关系: 逻辑关系 1 0 A and B A'->A,B'->B ...
- 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 ...
随机推荐
- Incompatible shapes during the half way training---Invalid argument: Incompatible shapes: [1,63,4] vs. [1,64,4]
这是tensorflow model 中我使用它的faster--cnn,但是就是训练过程中,代码执行到一半 一般是step=40~120的时候就报错了: INFO:tensorflow:global ...
- hive 安装centos7
wget mirror.bit.edu.cn/apache/hive/hive-2.3.4/apache-hive-2.3.4-bin.tar.gz 解压到/usr/local/apache-hive ...
- python 规范
摘自google. https://i.cnblogs.com/PostDone.aspx?postid=9753605&actiontip=%E4%BF%9D%E5%AD%98%E4%BF% ...
- 【Django】关于scss 的安装
今天看视频教程的时候发现老师的样式文件改用了scss(然鹅我买的1块钱特价课程其实是节选出来的,所以前面没有看到过关于scss的介绍) 然后我本以为把原来的css改名字为scss就行,然鹅没有效果. ...
- oracleXE数据库没有公开wm_concat函数, 需要手动添加
CREATE OR REPLACE TYPE wm_concat_impl AUTHID CURRENT_USER AS OBJECT ( curr_str ), STATIC FUNCTION od ...
- c++中的类(class)-----笔记(类多态)
1,多态是一种运行期绑定机制,通过这种机制,实现将函数名绑定到函数具体实现代码的目的.一个函数的名称与其入口地址是紧密相连的,入口地址是该函数在内存中的起始地址.如果对一个函数的绑定发生在运行时刻而非 ...
- FPGA基础知识1
1.乘法 在FPGA中,乘法运算可以分为 1)信号与信号之间的运算,用乘法器核实现: 2)常数与信号之间的运算,利用移位及加减法实现. A x 16 = A左移4位: A x 20 = A x 16 ...
- 设置获取cookie,setCookie,getCookie
设置cookie: function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getT ...
- 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛----随手记录帖
这是跟学长学姐组队来打的最爽的一次比赛了,也可能是互相组队最后一次比赛了,南哥和楼学姐,省赛之后就退役了,祝他们能考研和面试都有happy ending! 虽然最后没有把F题的n^2约数的数学题写完, ...
- 快速了解和使用Photon Server
https://blog.csdn.net/qq_36565626/article/details/78710787