#P10969. Katu Puzzle
Katu Puzzle
Problem Description
A Katu Puzzle is given in the form of a directed graph . Each edge is labeled with a Boolean operator (one of AND, OR, XOR) and an integer (). If we can find a value () for every vertex such that for every edge labeled with and , the following formula holds:
then this Katu Puzzle is solvable.
Given a Katu Puzzle, your task is to determine whether it is solvable.
Input Format
The first line contains two integers () and (), representing the number of vertices and the number of edges, respectively.
In the next lines, each line contains three integers (), (), , and an operator , describing the edge.
Output Format
Output one line containing or .
4 4
0 1 1 AND
1 2 1 OR
3 2 0 AND
3 0 0 XOR
YES
Hint
Translated by ChatGPT 5