You are walking down a street when, suddenly, you have a physiological urgency. You enter into a bar, and ask for the toilet. “To the end and to the right”, they tell you. Will you find the way?
Write a program that reads several maps of bars, and for each one tells if there is any path that first goes from the bottom to the very top, and then to the very right.
Input consists of several cases. Every case begins with two natural
numbers
and
,
followed by
rows with
characters each. A ‘.’ indicates a position which you can
pass by. An ‘X’ indicates a position which you cannot pass
by. The upper-right position always has a ‘.’. The rest of
positions of the right column always have an ‘X’. A special
case with
marks the end of input.
Print a line for each bar: if there is any way to the top and then to
the right, print “bufff”; otherwise, print
“ui ui ui”.
Input
5 6 .X.... .....X ...XXX .....X ...X.X 4 4 X... ..XX ...X .X.X 0 0
Output
bufff ui ui ui