Robotopia
You're playing Robotopia, a simulation game where you create and manage a bustling society of robots. There are many types of robots that can be created to perform various tasks throughout Robotopia's districts. There are some limitations: some robots have prerequisites that must be built first, and some types of robots cannot be placed into the same district.
To make life easier when designing Robotopia, you come up with a list of rules to follow. Each rule has one of the following formats:
Coexist A B: Robots of type A and type B must be placed in the same districtIncompatible A B: Robots of type A and type B must not be placed in the same districtDependsOn A B: Type A robots can only exist if type B robots also exist (B is a prerequisite for A)
You want to determine whether your list of rules is consistent with no contradictions. If the rules are valid, you can start building your robot metropolis!
Input
The first line contains a single integer
, the number of rules given.
The next lines contain strings
,
, and
— the rule, a robot of type
and a robot of type
. All strings are
characters or less.
Output
Output "Yes" if the list of rules are correct, and output "No" otherwise.
Clarification
- The robots are not necessarily built in the order they're given in the input. What matters is that the rules are consistent.
DependsOn A Bonly requires that type B robots are built before type A robots. It does not restrict which districts A or B can be placed in.
Example
Input 1
4
Coexist A B
Coexist C B
Incompatible C D
DependsOn E A
Output 1
Yes
Input 2
2
Coexist A B
Incompatible A B
Output 2
No
Comments