| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7949 | Accepted: 2914 |
Description
Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integer c (0 ≤ c ≤ 1). One Katu is solvable if one can find each vertex Via value Xi (0 ≤ Xi ≤ 1) such that for each edge e(a, b) labeled by op and c, the following formula holds:
Xa op Xb = c
The calculating rules are:
|
|
|
Given a Katu Puzzle, your task is to determine whether it is solvable.
Input
The first line contains two integers N (1 ≤ N ≤ 1000) and M,(0 ≤ M ≤ 1,000,000) indicating the number of vertices and edges.
The following M lines contain three integers a (0 ≤ a < N), b(0 ≤ b < N), c and an operator op each, describing the edges.
Output
Output a line containing "YES" or "NO".
Sample Input
4 4 0 1 1 AND 1 2 1 OR 3 2 0 AND 3 0 0 XOR
Sample Output
YES
题意:给出一个连通图对于每条边都有一种操作(and,or,xor),使两个端点的操作结果是c,问是否存在这样一个连通图,存在输出YES否者输出NO分析:裸的2-sat操作公式:i&j=1 (i-->i+n) (j-->j+n)i&j=0 (i+n-->j) (j+n-->i)i|j=1 (i-->j+n) (j-->i+n)i|j=0 (i+n-->i) (j+n-->j)i^j=1 (i-->j+n) (j+n-->i) (j-->i+n) (i+n-->j)i^j=0 (i-->j) (j-->i) (i+n-->j+n) (j+n-->i+n)程序;