原题链接

\(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的更多相关文章

  1. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

  2. 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 ...

  3. POJ-3678 Katu Puzzle 2sat

    题目链接:http://poj.org/problem?id=3678 分别对and,or,xor推出相对应的逻辑关系: 逻辑关系 1 0  A and B     A'->A,B'->B ...

  4. 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 ...

  5. 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 ...

  6. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

  7. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

  8. 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 ...

  9. POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Descr ...

随机推荐

  1. 随机数模块 random模块(1)

    1.取随机小数 import random print(random.random()) # (0,1) print(random.uniform(2,3)) # (n,m) 2.取随机整数 impo ...

  2. python教程_1

    1.2 不同应用领域的主流操作系统 (1)桌面操作系统 (2)服务器操作系统 (3)嵌入式操作系统 (4)移动设备操作系统 1>.桌面操作系统: Windows系列(微软的.net开发) 用户群 ...

  3. svn 更新lib库时,报错

    svn: E195012: Unable to find repository location for svn:// in revision 9718 Can't revert without re ...

  4. putty颜色调整

    右键window窗口--Changing Setting--window--Colours: * Default Foreground: 255/255/255 * Default Backgroun ...

  5. 单点登录(SSO)解决方案之 CAS服务端数据源设置及页面改造

    接上篇 单点登录(SSO)解决方案之 CAS 入门案例 服务端数据源设置: 开发中,我们登录的user信息都是存在数据库中的,下面说一下如何让用户名密码从我们的数据库表中做验证. 案例中我最终把cas ...

  6. 使用iptables禁止外网访问tomcat的8080端口

    如果项目同时使用了nginx反向代理服务器和tomcat等web服务器,并且两台服务器都暴露于公网中,那么通常我们会禁止外网直接访问tomcat,因为以下原因: 1.如果可以直接访问tomcat,那么 ...

  7. java面试题:多线程与并发

    多线程 关键词:线程池 Q:如何新建一个线程? 继承Thread,或者实现Runnable接口,或者通过Callable接口实现. Q:Callable怎么用? Callable可以作为FutureT ...

  8. Math.random控制随机数范围

    let minNum= parseInt(Math.random()*7) + 1 let maxNum= parseInt(Math.random()*83) + 1 生成7~83的随机整数

  9. 求组合数的O(n^2)和O(n)解法及模板

    概率论中的组合数应该比较熟悉吧,在数论中组合数也具有重大意义,下面介绍组合数的解法: 方法一O(n^2): 利用公式(n,m)=(n-1,m-1)+(n-1,m): 模板: #include<c ...

  10. openstack(Pike 版)集群部署(三)--- Glance 部署

    一.介绍 参照官网部署:https://docs.openstack.org/glance/queens/install/ 继续上一博客进行部署:http://www.cnblogs.com/weij ...