# 思路

$2-sat$问题，需要注意的是当两数$\&$起来为$1$时。必须全部为$1$，所以就从每个点的$0$$1$连边。同理，当两数$|$起来为$0$时，必须全部为$0$，所以就从每个点的$1$$0$连边。

# 代码

/*
* @Author: wxyww
* @Date:   2019-04-27 16:42:24
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 3000 + 10,M = 5000000 + 100;
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
struct node {
int v,nxt;
}e[M];
}
char s[5];
int sta[N],dfn[N],top,coljs,cnt,vis[N],low[N],col[N];
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
sta[++top] = u;
vis[u] = 1;
for(int i = head[u];i;i = e[i].nxt) {
int v = e[i].v;
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(vis[v]) low[u] = min(low[u],low[v]);
}
if(low[u] == dfn[u]) {
++coljs;
do {
int x = sta[top--];
col[x] = coljs;
vis[x] = 0;
}while(sta[top + 1] != u);
}
}
int main() {
for(int i = 1;i <= m;++i) {
scanf("%s",s + 1);
if(s[1] == 'O') {
}
else if(s[1] == 'X') {
}
else {
}
}
for(int i = 1;i <= n + n;++i) if(!dfn[i]) tarjan(i);
for(int i = 1;i <= n;++i) {
if(col[i] == col[i + n]) {
puts("NO");return 0;
}
}
puts("YES");
return 0;
}

===================================================================================

===================================================================================
posted @ 2019-04-29 08:11  wxyww  阅读(203)  评论(0编辑  收藏  举报