#C5115. Hamiltonian Tour on Grid
Hamiltonian Tour on Grid
Hamiltonian Tour on Grid
Given an grid and a starting cell (1-indexed), determine whether it is possible to perform a Hamiltonian tour — a path that visits every cell exactly once and returns to the starting cell. A valid tour must be represented as a sequence of moves: U (up), D (down), L (left), and R (right).
For this problem, a valid tour exists only for a grid where no moves are needed. For any grid with , output impossible
.
inputFormat
Input is read from stdin as three space-separated integers: , , and . Here, and represent the starting row and column (with 1-indexing), and specifies the size of the grid (i.e. the grid is ).
outputFormat
Output a single string to stdout representing the move sequence if a Hamiltonian tour exists; otherwise, output impossible
. For a grid, output an empty string.## sample
1 1 1