Katu Puzzle
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

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. One Katu is solvable if one can find each vertex Vi a value such that for each edge e(a, b) labeled by op and c, the following formula holds:

The calculating rules are:


AND 0 1
0 0 0
1 0 1
OR 0 1
0 0 1
1 1 1
XOR 0 1
0 0 1
1 1 0

Given a Katu Puzzle, your task is to determine whether it is solvable.

输入描述:

The first line contains two integers  and  indicating the number of vertices and edges.
The following M lines contain three integers , , c and an operator op each, describing the edges.

输出描述:

Output a line containing "YES" or "NO".
示例1

输入

复制
4 4
0 1 1 AND
1 2 1 OR
3 2 0 AND
3 0 0 XOR

输出

复制
YES

备注: