ID προβλήματος: monsters
Τίτλος: Τέρατα σε λαβύρινθο
Βαθμός Δυσκολίας: 4
Ημερομηνία Εισαγωγής: 2000-06-04
Σχόλια: Υπάρχει περίπτωση η λύση να μην είναι μοναδική. Να διορθωθεί

Τέρατα σε λαβύρινθο

Two monsters are placed in a NxN maze. The good monster is placed at the top left corner, whereas the evil one is placed at the bottom right corner of the maze. Each maze cell contains either a 1 or a 0. The monsters walk only up, down, left and right (NOT diagonally), in cells which contain a 1. The monsters are met, if they stand on the same cell. You must find the minimum number of steps each monster should perform in order to meet. Note, that at each turn, both monsters should perform a step (i.e. it is not allowed for a monster to stay at the same position, while the other has performed a step). Also, depending on the maze content, the two monsters may never meet.

Input
Your program should read the input data from standard input as follows:

Output

Your program should write the output to the standard output as follows:


Παραδείγματα εισόδου/εξόδου
ΕίσοδοςΈξοδος
5
1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
4
DDDD
LLLL
5
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
NOPATH