getting WA for fire escape routes FIRESC practice(easy)

please tell me…
for what test case i am getting WA…http://www.codechef.com/viewsolution/2389557

and also my program is taking too much time…
explain me another way to optimize my program…
Thankyou…