题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3062

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 1250
#define INF 0x3f3f3f
using namespace std; struct TwoSat{
int n;
vector<int> G[maxn*];
bool mark[maxn*];
int s[maxn*],cnt; void init(int n){
this->n = n;
memset(mark,,sizeof(mark));
for(int i=;i<n*;i++) G[i].clear();
}
bool dfs(int u){
if(mark[u^]) return false;
if(mark[u]) return true;
mark[u] = true;
s[cnt++] = u;
for(int i=;i<G[u].size();i++){
if(!dfs(G[u][i])) return false;
}
return true;
} void add_clause(int u,int uval,int v,int vval){ //这儿有问题
u = u* + uval; //u,v有矛盾;
v = v* + vval;
G[u].push_back(v^);
G[v].push_back(u^);
} bool solve(){
for(int i=;i<n*;i+=){
if(!mark[i] && !mark[i+]){ //为啥这个地方不回溯;
cnt = ;
if(!dfs(i)){
while(cnt > ) mark[s[--cnt]] = false;
if(!dfs(i+)) return false;
}
}
}
return true;
}
}solver; int main()
{
//freopen("input.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m)==){
solver.init(n);
for(int i=;i<=m;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
solver.add_clause(a,c,b,d);
}
if(solver.solve()) printf("YES\n");
else printf("NO\n");
}
}

hdu 3062 2-sat入门题的更多相关文章

  1. hdu 3062+1824(2-sat入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3062 思路:根据矛盾关系连边(如果a与b矛盾,则连边a'->b,b'->a),然后强连通缩 ...

  2. hdu 1086(计算几何入门题——计算线段交点个数)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...

  3. HDU 1880 字符串hash 入门题

    Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔 ...

  4. X问题 HDU - 1573(excrt入门题)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. hdu 1358 Period(KMP入门题)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. HDU - 1520 树形DP入门题

    写了两种DP,第一种是按照自己习惯来xjb敲的,第二种参考别人 熟悉一下树形DP的套路 dp[i][]是维护i及以下的关系最优值的,所以我觉得两次DP记忆搜索之间不清-1应该是正确的(也就做了一次加法 ...

  7. hdu 2089 数位dp入门题

    #include<stdio.h> //dp[i][0]代表不存在不吉利数字 //dp[i][1]代表不存在不吉利数字但是以2开头 //dp[i][2]代表存在不吉利数字 #define ...

  8. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  9. hdu 1465:不容易系列之一(递推入门题)

    不容易系列之一 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  10. hdu 2191 珍惜现在,感恩生活 多重背包入门题

    背包九讲下载CSDN 背包九讲内容 多重背包: hdu 2191 珍惜现在,感恩生活 多重背包入门题 使用将多重背包转化为完全背包与01背包求解: 对于w*num>= V这时就是完全背包,完全背 ...

随机推荐

  1. Android OpenGL ES 3.0 纹理应用

    本文主要演示OpenGL ES 3.0 纹理演示.接口大部分和2.0没什么区别,脚本稍微有了点变化而已. 扩展GLSurfaceView package com.example.gles300; im ...

  2. 如何利用C#编写网页投票器程序 如何使用代理来投票 代理IP来投票

      一.前言看个图,了解下投票的过程.提交投票信息投票页 ――――――――>投票信息处理页反馈投票结果(请求页)<―――――――(响应页)一般情况下,填写投票信息,然后点提交按钮发送到响应 ...

  3. UITableViewCell 左滑删除

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return Y ...

  4. vs 2013 编译zlib

    zlib下载地址: http://pan.baidu.com/s/1pJqTcoV \zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln 打开这个文件, 根据提示, ...

  5. 【POJ3468】【树状数组区间修改】A Simple Problem with Integers

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  6. underscorejs-partition学习

    2.25 partition 2.25.1 语法: _.partition(list, predicate, [context]) 2.25.2 说明: 拆分list为两个数组. 第一个数组的元素都满 ...

  7. 对象的内置属性和js的对象之父Object()

    js中对象有constructor,valueOf(),toString()等内置属性和方法; 创建一个空对象的方法: var o = {}; 或者 var o= new Object(); o.co ...

  8. c#的异或运算符

    int a = 5; int b = 30; Console.WriteLine(a^b); Console.ReadKey();  输出结果是27 这是因为 5的二进制是0000 010130的二进 ...

  9. Bootstrap_Javascript_弹出框

    HTML: <button type="button" class="btn btn-default" data-container="body ...

  10. input file文件上传样式

    <style>    .file-group {        position: relative;        width: 200px;        height: 80px;  ...