MOG Round #13Ended 
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 \le c \le 1)$. One Katu is solvable if one can find each vertex $V_i$ a value $X_i$ $(0 \le X_i \le 1)$ such that for each edge $e(a, b)$ labeled by $op$ and $c$, the following formula holds:
$X_a$ $op$ $X_b = c$
The calculating rules are:



Given a Katu Puzzle, your task is to determine whether it is solvable.
The first line contains two integers $N$ $(1 \le N \le 1000)$ and $M$ $(0 \le M \le 10^6)$ indicating the number of vertices and edges. The following $M$ lines contain three integers $a$ $(0 \le a \lt N)$, $b$ $(0 \le b \lt N)$, $c$ and an operator $op$ each, describing the edges.
Output a line containing "YES" or "NO".