比较经典的建图,详见进阶指南

2-sat一般要用到tarjan来求强连通分量

/*2-sat要加的是具有强制关系的边*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 2005
#define M 2000005
struct Edge{int to,nxt;}e[M<<];
int n,m,head[N],tot;
void init(){
memset(head,-,sizeof head);
}
void add(int u,int v){
e[tot].to=v;
e[tot].nxt=head[u];
head[u]=tot++;
} int low[N],dfn[N],cnt,id[N],ind,stk[N],top,ins[N];
void tarjan(int x){
dfn[x]=low[x]=++ind;
stk[++top]=x;ins[x]=;
for(int i=head[x];i!=-;i=e[i].nxt){
int y=e[i].to;
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(ins[y])
low[x]=min(low[x],low[y]);
}
if(dfn[x]==low[x]){
cnt++;int y;
do{
y=stk[top--];
ins[y]=;
id[y]=cnt;
}while(x!=y);
}
} int main(){
init();
int a,b,c;
char op[];
cin>>n>>m;
for(int i=;i<=m;i++){
scanf("%d%d%d %s",&a,&b,&c,op);
a++,b++;
if(op[]=='A'){
if(c==)add(a+n,b),add(b+n,a);
if(c==)add(a,a+n),add(b,b+n);
}
if(op[]=='O'){
if(c==)add(a+n,a),add(b+n,b);
if(c==)add(a,b+n),add(b,a+n);
}
if(op[]=='X'){
if(c==)add(a,b),add(b,a),add(a+n,b+n),add(b+n,a+n);
if(c==)add(a,b+n),add(a+n,b),add(b,a+n),add(b+n,a);
}
}
for(int i=;i<=*n;i++)
if(!dfn[i])tarjan(i);
for(int i=;i<=n;i++)
if(id[i]==id[i+n]){
puts("NO");
return ;
}
puts("YES");
}

2-sat——poj3678经典建图的更多相关文章

  1. hdoj--5093--Battle ships(二分图经典建图)

    Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  2. poj--1149--PIGS(最大流经典建图)

    PIGS Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit Status D ...

  3. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

  4. POJ1149 最大流经典建图PIG

    题意:       有一个人,他有m个猪圈,每个猪圈里都有一定数量的猪,但是他没有钥匙,然后依次来了n个顾客,每个顾客都有一些钥匙,还有他要卖猪的数量,每个顾客来的时候主人用顾客的钥匙打开相应的门,可 ...

  5. POJ 2226 最小点覆盖(经典建图)

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8881   Accepted: 3300 Desc ...

  6. BZOJ-1822 Frozen Nova 冷冻波 计(jie)算(xi)几何+二分+最大流判定+经典建图

    这道逼题!感受到了数学对我的深深恶意(#‵′).... 1822: [JSOI2010]Frozen Nova 冷冻波 Time Limit: 10 Sec Memory Limit: 64 MB S ...

  7. zoj 3460 Missile【经典建图&&二分】

    Missile Time Limit: 2 Seconds      Memory Limit: 65536 KB You control N missile launching towers. Ev ...

  8. poj 1149 PIGS【最大流经典建图】

    PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18727   Accepted: 8508 Description ...

  9. Leapin' Lizards(经典建图,最大流)

    Leapin' Lizards http://acm.hdu.edu.cn/showproblem.php?pid=2732 Time Limit: 2000/1000 MS (Java/Others ...

随机推荐

  1. maven项目打成jar包之前需要在pom文件做的准备工作

    文章目录 pom.xml 很多时候在eclipse中没问题java -jar没有主类,或者classnotfound pom.xml <build> <plugins> < ...

  2. Sigils of Elohim

    题目大意 见游戏链接https://store.steampowered.com/app/321480/. 分析 作为一个程序猿,我拒绝用人脑dfs. 代码如下 #include <bits/s ...

  3. neo4j采坑记

    1.安装后启动不起来,解决方案: https://stackoverflow.com/questions/38607283/failed-to-start-neo4j-service  2.一直启动不 ...

  4. mysql主从复制原理分析

    1.主从复制这类NFS存储数据通过inotify+rsync同步到备份的NFS服务器,只不 过Mysql的复制方案是其自带的工具inotify 是一种文件系统的变化通知机制,如文件增加.删除等事件可以 ...

  5. scrapy 多个爬虫运行

    from scrapy import cmdline import datetime import time import os import scrapy from scrapy.crawler i ...

  6. Ubuntu18.04 安装搜狗拼音

    参考文章:https://blog.csdn.net/fx_yzjy101/article/details/80243710 1. 安装fcitx sudo apt-get install fcitx ...

  7. mysql UDF提权问题

    测试UDF提权,时候遇到问题,创建函数shell提示存在 当执行操作的时候又提示,shell函数不存在. FUNCTION mysql.shell does not exist 如果在测试环境下,一般 ...

  8. foreach循环的简单写法

    简单的foreach循环写法: pickedItems.ForEach(item => { this.List.Remove(item); }); //注意,List 必须和pickedItem ...

  9. bzoj 3579: 破冰派对

    题意: 给你一个图,问你有多少个方案把他分成连个新的图.使得一个图是一个团,另外一个是独立集 一些闲话: 以前做过一次这个题..当时听说爆搜可以过,就无脑莽过去了.. 也没有思考为什么爆搜能过,或者有 ...

  10. js拼接HTML onclick传参,,页面转义符

    字符串 1 使用" .比如: ("'+key+'")例: htmlStr = htmlStr + '<span><img src="'+src ...