Bad Maths
View as PDFYou are given equations over variables that each take a value of either or
. Every equation has the form
, where
and
are
variables and
is either
or
.
Process the equations one by one. For each equation, decide whether it is
consistent with the equations accepted so far: that is, whether there still
exists an assignment of to all variables that satisfies every previously
accepted equation together with the current one.
- If it is consistent, output
Yesand accept the equation. - If it is inconsistent, output
Noand discard the equation (do not use it when checking later equations).
Input
The first line contains an integer , the number of equations.
Each of the following lines contains
a b c, meaning ,
where
and
are variable names (nonempty strings of lowercase English
letters) and
is either
or
.
Output
For each equation, output a line containing Yes if it is consistent with the
equations accepted so far, or No otherwise.
Constraints
Example 1
Input
10
c c -1
a b 1
c c 1
d e 1
c e 1
c a 1
b e -1
b b -1
b b -1
e b 1
Output
No
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
Explanation
is impossible for
, so the answer is
Noand the equation is discarded.is accepted.
always holds, so it is accepted.
- The next three equations are all compatible with an assignment and are
accepted. Together they force
and
to have the same sign, so
must equal
.
- Therefore
is inconsistent and discarded.
- Both copies of
are impossible and discarded.
matches the forced relation, so it is accepted.
Example 2
Input
20
c b 1
e c -1
b b 1
d f -1
a d -1
b c 1
d b 1
f e -1
d b 1
e d 1
c d 1
f a -1
e e 1
c b 1
d d 1
d e -1
b a 1
b a 1
d f 1
a f -1
Output
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
Comments