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 ...
随机推荐
- table-cell http://www.cnblogs.com/StormSpirit/archive/2012/10/24/2736453.html
http://www.cnblogs.com/StormSpirit/archive/2012/10/24/2736453.html
- Python教程_简介2
人生苦短,我用Python--Life is short,you need Python. https://www.bilibili.com/video/av14184325/?p=101 Pytho ...
- Unity入门&物理引擎
一.Unity六大模块 首先,Unity界面有六大模块,分别是:Hierarchy,Scene,Game,Inspector,Project,Console.下面对这六个视图的功能进行详解. 1.Hi ...
- metasploit framework(十一):获取漏洞信息
查看参数 这个模块运行需要一个session 所以需要先获取到一个session 就获得了一个session 再回到枚举补丁模块 添加session 查看参数看到session已经添加上去了 run ...
- python3使用paramiko操作远程机器
目标:有A和B两台机器,希望在机器A上操作B上的脚本 解决方法:使用paramiko实现操作远程机器 1.安装paramiko 安装第三方包[pip3 install paramiko] ...
- 强制改变css样式优先级
.list{ left:20px!important; } css !important作用是提高指定CSS样式规则的应用优先权. !important是CSS1就定义的语法,作用是提高指定样式规则的 ...
- java面试题:多线程与并发
多线程 关键词:线程池 Q:如何新建一个线程? 继承Thread,或者实现Runnable接口,或者通过Callable接口实现. Q:Callable怎么用? Callable可以作为FutureT ...
- Jenkins+sonar7.3集成
Jenkins安装请参考:https://blog.csdn.net/CheNorton/article/details/50327825?utm_source=copy Jenkins更新请参考:h ...
- c++中的类(class)-----笔记(类模板)
1,一个模板类至少具有一个类参数,类参数是个符号以表示将要被某个确定数据类型代替的类型. #include<iostream> #include<string> using n ...
- STL-queue和循环队列基本操作的实现
2018-11-13-17:53:44 1.可增长循环队列 队列是一种特殊的线性表,是一种先进先出(FIFO)的数据结构.它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入 ...