POJ 3678 Katu Puzzle 2-SAT 强连通分量 tarjan
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的更多相关文章
- poj 3678 Katu Puzzle(Two Sat)
题目链接:http://poj.org/problem?id=3678 代码: #include<cstdio> #include<cstring> #include<i ...
- 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 ...
- POJ 3678 Katu Puzzle (经典2-Sat)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- 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 ...
- POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9987 Accepted: 3741 Descr ...
- POJ 3678 Katu Puzzle (2-SAT)
Katu Puzzle Time Limit: 1000MS ...
- 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 ...
- POJ 1236 Network of Schools(强连通分量/Tarjan缩点)
传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...
- POJ 3678 Katu Puzzle(强连通 法)
题目链接 题意:给出a, b, c 和操作类型 (与或异或),问是否满足所有的式子 主要是建图: 对于 and , c == 1: 说明 a 和 b都是1,那么 0 就不能取, a' -> a ...
随机推荐
- c# 生成随机N位数字串(每位都不重复)
/// <summary> /// 生成随机数字窜 /// </summary> /// <param name="Digit">位数</ ...
- [Openwrt扩展中篇]添加Aria2和webui
上一篇说了我构建了简单的网络硬盘,这一篇说的是我构造的aria2和webui,大概是这样我觉得有了网络硬盘,那么我是不是可以远程下载呢,翻阅了网上资料发现迅雷的Xware貌似不更新了,然后我发现了ar ...
- mysql条件查询中AND与OR联合使用的注意事项!
mysql查询中经常会用到AND与OR一起使用的情况,可如果写法不对,往往会起到相反的效果,这不,前几天就碰到了,最后测试果然提了一堆bug!!!! 废话就不多说了,主要总结一下几点: 一 当mysq ...
- 内核定时器的使用(好几个例子add_timer)【转】
转自:http://blog.csdn.net/jidonghui/article/details/7449546 LINUX内核定时器是内核用来控制在未来某个时间点(基于jiffies)调度执行某个 ...
- 高性能.NET MVC之QMVC!
ASP.NET!这个词代表者一个单词Fat!因为他总是捆绑着太多的太多的类,太多太多的各种功能!你也许会用到,如果你反编译或阅读他们开源的源码,你会不会犹如在大海中找不到方向?不管是Web form ...
- 五、springcloud之客户端负载均衡Ribbon
一.简介 在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于http restful的.Spring cloud有两种服务调用方式: 一种是ribbon+restTemplate, ...
- js中字符串的常用方法
一.普通方法 1.字符方法 动态方法:1.str.charAt(index); 返回子字符串,index为字符串下标,index取值范围[0,str.length-1] 动态方法:2.str.cha ...
- 数据结构之 栈 (Python 版)
数据结构之 栈 (Python 版) -- 利用线性表实现栈 栈的特性: 后进先出 基于顺序表实现栈 class SStack(): ''' 基于顺序表 实现的 栈类 ''' def __init__ ...
- 安卓ios各版本及分辨率占比
Google Play 安装统计数据 只有安卓的 https://developer.android.com/about/dashboards/index.html?hl=zh-cn 腾讯移动分析 安 ...
- java基础32 List集合下的ArrayList集合
单例集合体系: ---------| collection 单例集合的根接口--------------| List 如果实现了list接口的集合类,具备的特点:有序,可重复 注:集合 ...