# 题目大意：

$op$$op$$OR$$OR$$AND$$AND$, $XOR$$XOR$中一个

1 ≤ N ≤ 1000
0 ≤ M ≤ 1,000,000

# 分析：

$i$$i$ $and$$and$ $j=0$$j = 0$

${i}^{\prime }->j$$i'->j$${j}^{\prime }->i$$j'->i$

$i$$i$ $and$$and$ $j=1$$j = 1$

$i$$i$ $or$$or$ $j=1$$j = 1$

$i->{j}^{\prime }$$i->j'$$j->{i}^{\prime }$$j->i'$

$i$$i$ $or$$or$ $j=0$$j = 0$

${i}^{\prime }->i$$i'->i$${j}^{\prime }->j$$j'->j$

$i$$i$ $xor$$xor$ $j=1$$j = 1$

$i->{j}^{\prime }$$i->j'$ ${i}^{\prime }->j$$i'->j$
$j->{i}^{\prime }$$j->i'$${j}^{\prime }->i$$j'->i$

$i$$i$ $xor$$xor$ $j=0$$j = 0$

$i->j$$i->j$${i}^{\prime }->{j}^{\prime }$$i'->j'$
$j->i$$j->i$${j}^{\prime }->{i}^{\prime }$$j'->i'$

# 代码：

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define INF 2333333
#define M 1200005
#define N 2005

using namespace std;

struct node {
int u, v, next;
}a[M];

int Ls[N], Belong[N], order[N], tot, cnt, n, m;
char str[10];
bool vis[N];

void addedge(int u, int v) {
cnt++;
a[cnt].u = u;
a[cnt].v = v;
a[cnt].next = Ls[u];
Ls[u] = cnt;
}

void dfs(int x, int times) {
vis[x] = 1;
for (int i = Ls[x]; i; i = a[i].next)
if (!vis[a[i].v]) dfs(a[i].v, times);
if (!times) {
tot++;
order[tot] = x;
} else Belong[x] = tot;
}

void Kosaraju() {
for (int i = 1; i <= 2 * n; i++) vis[i] = 0;
tot = 0;
for (int i = 1; i <= 2 * n; i++)
if (!vis[i]) dfs(i, 0);

int rp = cnt; cnt = 0;
for (int i = 1; i <= 2 * n; i++) Ls[i] = 0;
for (int i = 1; i <= rp; i++) addedge(a[i].v, a[i].u);

for (int i = 1; i <= 2 * n; i++) vis[i] = 0;
tot = 0;
for (int i = 2 * n; i >= 1; i--) {
int j = order[i];
if (!vis[j]) {
tot++;
dfs(j, 1);
}
}
}

int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v, w;
scanf("%d %d %d %s", &u, &v, &w, str);
u++, v++;
if (strcmp(str, "OR") == 0) {
if (w == 1) {
} else {
}
}

if (strcmp(str, "AND") == 0) {
if (w == 1) {
} else {
}
}

if (strcmp(str, "XOR") == 0) {
if (w == 1)
{
} else {
addedge(u + n, v + n);
addedge(v + n, u + n);
}
}
}
Kosaraju();
bool check = 1;
for (int i = 1; i <= n; i++)
if (Belong[i] == Belong [i+n]) check = 0;
if (check) printf("YES\n");
else printf("NO\n");
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120