http://poj.org/problem?id=3678

给m条连接两个点的边,每条边有一个权值0或1,有一个运算方式and、or或xor,要求和这条边相连的两个点经过边上的运算后的结果是边的权值。问存不存在使所有边都符合条件的给点赋值的方法。

2-SAT的各种连法都有了。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=;
int n,m;char s[]={};
struct nod{
int y,next;
}e[maxn*maxn];
int head[maxn]={},tot=;
inline void init(int x,int y){e[++tot].y=y;e[tot].next=head[x];head[x]=tot;}
int low[maxn]={},vis[maxn]={},dfn[maxn]={},cnt=;
int sta[maxn]={},tai=,bel[maxn]={},tn=;
void tarjan(int x){
low[x]=dfn[x]=++cnt;vis[x]=;sta[++tai]=x;
for(int i=head[x];i;i=e[i].next){
int y=e[i].y;
if(!dfn[y]){
tarjan(y);if(low[x]>low[y])low[x]=low[y];
}
else if(vis[y]&&dfn[y]<low[x])low[x]=dfn[y];
}
if(low[x]==dfn[x]){
int w;++tn;
do{
w=sta[tai--];
vis[w]=;bel[w]=tn;
}while(w!=x);
}
}
int main(){
scanf("%d%d",&n,&m);int x,y,v;
for(int i=;i<=m;i++){//x+n 1 x 0
scanf("%d%d%d",&x,&y,&v);scanf("%s",s);++x;++y;
if(s[]=='A'){
if(v==){
init(x+n,y+n);init(y+n,x+n);
init(y,x+n);init(x,y+n);
}else {init(x+n,y);init(y+n,x);}
}
else if(s[]=='O'){
if(v==){init(x,y+n);init(y,x+n);}
else{
init(x,y);init(y,x);
init(x+n,y);init(y+n,x);
}
}
else{
if(v==){
init(x,y+n);init(y+n,x);
init(x+n,y);init(y,x+n);
}
else{
init(x+n,y+n);init(y+n,x+n);
init(x,y);init(y,x);
}
}
}
for(int i=;i<=*n;i++)if(!dfn[i])tarjan(i);
int f=;
for(int i=;i<=n;i++){
if(bel[i]==bel[i+n]){
f=;break;
}
}
if(f)printf("NO\n");
else printf("YES\n");
return ;
}

POJ 3678 Katu Puzzle 2-SAT 强连通分量 tarjan的更多相关文章

  1. poj 3678 Katu Puzzle(Two Sat)

    题目链接:http://poj.org/problem?id=3678 代码: #include<cstdio> #include<cstring> #include<i ...

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

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

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

  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,合取范式大集合)

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

  6. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

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

  8. POJ 1236 Network of Schools(强连通分量/Tarjan缩点)

    传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...

  9. POJ 3678 Katu Puzzle(强连通 法)

    题目链接 题意:给出a, b, c 和操作类型 (与或异或),问是否满足所有的式子 主要是建图: 对于 and , c == 1: 说明 a 和 b都是1,那么 0 就不能取, a' -> a ...

随机推荐

  1. 音频增益响度分析 ReplayGain 附完整C代码示例【转】

    转自:http://www.cnblogs.com/cpuimage/p/8846951.html 人们所熟知的图像方面的3A算法有: AF自动对焦(Automatic Focus)自动对焦即调节摄像 ...

  2. linux用户权限 -> 系统用户管理

    用户基本概述: Linux用户属于多用户操作系统,在windows中,可以创建多个用户,但不允许同一时间多个用户进行系统登陆,但是Linux可以同时支持多个用户同时登陆操作系统,登陆后互相之间并不影响 ...

  3. 05 Diagnostics 诊断

    Diagnostics 诊断 Introduction 介绍 Profiling 分析 Tracing 跟踪 Debugging 调试 Runtime statistics and events 运行 ...

  4. 关于 JVM 内存的 N 个问题(转)

    JVM的内存区域是怎么划分的? JVM的内存划分中,有部分区域是线程私有的,有部分是属于整个JVM进程:有些区域会抛出OOM异常,有些则不会,了解JVM的内存区域划分以及特征,是定位线上内存问题的基础 ...

  5. php修改文件上传大小限制

    上传一个20M文件的时候php报如下错误,是php上传文件大小限制引起 POST Content-Length of 19248654 bytes exceeds the limit of 83886 ...

  6. 追MM与设计模式

    1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳和肯德基就是生产鸡翅 ...

  7. Codeforces 332B Maximum Absurdity(DP+前缀和处理)

    题目链接:http://codeforces.com/problemset/problem/332/B 题目大意:给你n个数和一个整数k,要求找到不相交的两个长度为k的区间,使得区间和最大,输出这两个 ...

  8. svn 批量添加命令

    svn st | awk '{if ($1 == "?") {print $2} }' | xargs svn add

  9. CVE-2013-3893

    前方高能!!!这篇博文比较长,因为我把完整的调试过程都记录下来了,感兴趣的童鞋可以看下.没有耐心的童鞋可以直接跳到最后看总结:) Microsoft Internet Explorer 远程代码执行漏 ...

  10. 企业级Docker Registry —— Harbor搭建和使用

    本节内容: Harbor介绍 安装部署Harbor 环境要求 环境信息 安装部署harbor 配置harbor 配置存储 完成安装和启动harbor 访问Harbor 修改管理员密码 启动后相关容器 ...