传送门

2-sat问题,只需要判断yes或no

所以可以直接连边,缩点,判断同一组的是否在同一个块中。

 #include <cstdio>
#include <stack>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1000001 int n, m, cnt, idx, sz;
int head[N], to[N << ], next[N << ], dfn[N], low[N], belong[N];
bool ins[N], flag;
std::stack <int> s; inline void add(int x, int y)
{
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
} inline void tarjan(int u)
{
int i, v;
dfn[u] = low[u] = ++idx;
ins[u] = ;
s.push(u);
for(i = head[u]; i != -; i = next[i])
{
v = to[i];
if(!dfn[v])
{
tarjan(v);
low[u] = std::min(low[u], low[v]);
}
else if(ins[v]) low[u] = std::min(low[u], dfn[v]);
}
if(low[u] == dfn[u])
{
++sz;
do
{
v = s.top();
s.pop();
ins[v] = ;
belong[v] = sz;
}while(u != v);
}
} int main()
{
int i, j, a, b, c, d;
while(~scanf("%d", &n))
{
memset(head, -, sizeof(head));
memset(ins, , sizeof(ins));
memset(dfn, , sizeof(dfn));
idx = cnt = sz = ;
while(!s.empty()) s.pop();
scanf("%d", &m);
for(i = ; i <= m; i++)
{
scanf("%d %d %d %d", &a, &b, &c, &d);
a = (a << ) + c;
b = (b << ) + d;
add(a, b ^ );
add(b, a ^ );
}
for(i = ; i < n << ; i++)
if(!dfn[i])
tarjan(i);
flag = ;
for(i = ; i < n; i++)
if(belong[i << ] == belong[(i << ) ^ ])
flag = ;
if(flag) printf("NO\n");
else printf("YES\n");
}
return ;
}

[HDU3062]Party(2-sat)的更多相关文章

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

  2. 学习笔记(two sat)

    关于two sat算法 两篇很好的论文由对称性解2-SAT问题(伍昱), 赵爽 2-sat解法浅析(pdf). 一些题目的题解 poj 3207 poj 3678 poj 3683 poj 3648 ...

  3. Katu Puzzle POJ - 3678 (2 - sat)

    有N个变量X1X1~XNXN,每个变量的可能取值为0或1. 给定M个算式,每个算式形如 XaopXb=cXaopXb=c,其中 a,b 是变量编号,c 是数字0或1,op 是 and,or,xor 三 ...

  4. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  5. spring定时任务详解(@Scheduled注解)( 转 李秀才的博客 )

    在springMVC里使用spring的定时任务非常的简单,如下: (一)在xml里加入task的命名空间 xmlns:task="http://www.springframework.or ...

  6. MongoDB 聚合管道(Aggregation Pipeline)

    管道概念 POSIX多线程的使用方式中, 有一种很重要的方式-----流水线(亦称为"管道")方式,"数据元素"流串行地被一组线程按顺序执行.它的使用架构可参考 ...

  7. mysql触发器,答题记录表同步教学跟踪(用户列表)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVQAAAOOCAIAAABgEw4AAAAgAElEQVR4nOy92VcT27r/zX+xLtflvt

  8. Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)

    0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 脚本 ...

  9. Quartz.net(调度框架) 使用Mysql作为存储

    最近公司的做的项目中涉及到配置任务地址然后按照配置去目标地址提取相关的数据,所以今天上午在Internet上查看有关定时任务(调度任务)的相关信息,筛选半天然后查找到Quartz.net. Quart ...

  10. mysql 函数编程大全(持续更新)

    insert ignore insert ignore表示,如果中已经存在相同的记录,则忽略当前新数据 如果您使用一个例如“SET col_name = col_name + 1”的赋值,则对位于右侧 ...

随机推荐

  1. C++ thread operator= 右值引用 vector foreach

    这是 thread 的construct定义: default (1) thread() noexcept; initialization (2) template <class Fn, cla ...

  2. qconbeijing2014

    http://2014.qconbeijing.com/videoslides.html   周一 周二 周三 周四 周五 周六 2014年5月19日 Deep Dive into Amazon's ...

  3. C#基础学习3

    运算符,表达式!

  4. IO(下)

    7. 标准输入.输出流 7.1 标准输入流 源数据源是标准输入设备(键盘.鼠标.触摸屏)等输入设备.在java中用http://System.in 得到一个 InputStream 字节输入流. 需求 ...

  5. VS2013编译libjpeg库

    第一步:找到刚刚解压出来的“jpeg-9a”文件夹下面的“makefile.vc”文件,用记事本或Notepad++等编辑工具打开,然后找到里面的“!include <win32.mak> ...

  6. Load average in Linux的精确含义

    Man 上的解释: load average System load averages is the average number of processes that are either in a ...

  7. php用面向对象从mysql取数据

    <?php //建立数据库的链接@$_mysqli = new mysqli('localhost','root','123456','dbname');if(mysqli_connect_er ...

  8. COGS 827. [Tyvj Feb11] 网站计划

    输入文件:web.in   输出文件:web.out   简单对比时间限制:1 s   内存限制:128 MB 描述 Description     Tyvj的Admin--zhq同学将在寒假开始实行 ...

  9. JOIN和UNION的区别

    join 是两张表根据条件相同的部分合并生成一个记录集. SELECT Websites.id, Websites.name, access_log.count, access_log.dateFRO ...

  10. isEqual ,判断两个对象或变量是否相等

    function isEqual(a, b) { //如果a和b本来就全等 if (a === b) { //判断是否为0和-0 return a !== 0 || 1 / a === 1 / b; ...