Chairs
시간 제한1초메모리 제한1024 MB
좌상단에서 우하단까지 최단 경로 중 모든 의자 칸을 지나는 경로를 찾고, 불가능하면 Impossible을 출력하며 가능하면 사전순으로 가장 작은 이동 문자열을 출력한다.
문제
Ostap and Kisa found themselves at a chair sale. They are facing two problems. First, they must leave the sale as soon as possible, because their rival company, represented by father Theodore, is breathing down their necks; second, they must get all chairs at the sale.
The sale site is a rectangular table of rows and columns, with some of its cells occupied by chairs that need to be collected. Initially our enterpreneurs are in the top-left corner --- the cell with the coordinates , and the exit is located in the bottom-right corner --- the cell with the coordinates . A single move can transfer them from a given sell to any of adjacent by a side cells. Passing through a cell with a chair, they take the chair with them. Find a shortest path from the starting to the ending cell. Among all such paths, find one passing through all cells with chairs, or find out if such a path doesn't exist.
입력
The first line contains three integers: , , --- size of the table and the number of chairs, respectively (, ).
The following lines of the input data each contain two integers: --- the number of the row in which the -th chair is located, and --- the number of the column in which the -th chair is located (, ). A single cell cannot contain multiple chairs.
출력
If collecting all chairs along any single shortest path is impossible, print a single word <<Impossible>> (without brackets) in the output file.
If such a path exists, print it as a line containing the sequence of moves, with each move coded by a single symbol according to the following:
R--- move right;D--- move down;
If several solutions are possible, print the lexicographically smallest solution.