Problem E
Hogwarts
The Hogwarts School of Witchcraft and Wizardry is the home
of many students during the school year. The school has many
rooms connected by corridors and stairs. Each room has four
exits labelled by the integers
New students often have difficulty finding their way,
especially since the corridors and stairs are regularly moving,
disconnecting and reconnecting different rooms! Luckily, these
reconfigurations only take place when no one is walking in the
school. All you want to know is how to get from the entrance to
the dormitory. A senior student has given you instructions as a
sequence of numbers among
You carefully followed the instructions and arrived at the dormitory. However, the way the rooms are connected to each other has changed after the senior student gave you the instructions, and you just happen to arrive at the same destination even if the rooms you encountered along the way may be completely different.
You wonder if you are just lucky, or if the reconfiguration of the corridors and stairs ensures that the instructions still lead you to the same destination. Isn’t that magical?
You will be given a configuration of the school when the senior student walked from the entrance to the dormitory, as well as the configuration of the school when you start following the given instructions. You want to know if every possible sequence of instructions that led the senior student to the dormitory will also lead you to the dormitory in the configuration you walk through. Both the senior student and you start walking from the entrance of the school.
Input
The first line of input contains a single integer
The next
The
Output
If it is not possible for the senior student to walk from the entrance to the dormitory, display Impossible.
If it is possible, display Yes if you can get from the entrance to the dormitory by following any sequence of instructions taking the senior student from the entrance to the dormitory. Otherwise, display No.
Sample Input 1 | Sample Output 1 |
---|---|
4 1 1 1 2 2 2 2 3 3 3 3 4 0 0 0 0 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 |
Yes |
Sample Input 2 | Sample Output 2 |
---|---|
4 1 1 1 2 2 2 2 3 3 3 3 4 0 0 0 0 2 2 2 2 3 3 3 3 4 4 4 4 0 0 0 0 |
No |