Problem C
Mårten's Theorem

According to Mårten’s Theorem, everything which rhymes is the same thing. For example, Sheep is the same thing as Heap, Dictionary Attack is the same thing as Stack, and Tree is the same thing as the Mediterranean Sea.
Strangely, some people have objected to Mårten’s Theorem, despite being rigorously proved by Johan’s infinitely many self-referencing recursive lemmas. You have been given the task of deciding if a number of statements are consistent under Mårten’s Theorem.
You will be given a number of statements of the form
"
However, you must also take Mårten’s theorem into account.
For the sake of simplicity, we say that two words rhyme if the
last
Note that words which do not appear in any statement do not exist, and should not be considered rhyming with anything. That is, the two words foo and moo do not rhyme with each other, unless the word oo or o exists in the input.
Input
The first line consists of an integer
Output
Output should consist of the string "yes", if the statements are consistent with each other, i.e. everything which is stated to be the same either explicitly or by Mårten’s Theorem, really is the same. If you can find contradiction, output the string "wait what?".
Sample Input 1 | Sample Output 1 |
---|---|
4 herp is derp derp is herp herp is herp derp is derp |
yes |
Sample Input 2 | Sample Output 2 |
---|---|
3 oskar not lukas oskar is poptart lukas is smart |
wait what? |
Sample Input 3 | Sample Output 3 |
---|---|
1 moo not foo |
yes |
Sample Input 4 | Sample Output 4 |
---|---|
2 moo not foo oo is blah |
wait what? |