407520: GYM102822 A A Colorful Grid

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. A Colorful Gridtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There is a grid with $$$n$$$ rows and $$$m$$$ columns, and $$$n \times m$$$ is even. The grid is painted with $$$\frac{n \times m}{2}$$$ kinds of colors. Each kind of color should occupy exactly two adjacent blocks. Two blocks are adjacent means they share an edge in the grid. We define $$$(x,y)$$$ as the block in the $$$x$$$-th row and $$$y$$$-th column.

Little Horse is walking on the grid. Each time he can move to an adjacent block, but he cannot move to the one that shares the same color with his current position. Now, we give you $$$k$$$ conditions. In each condition, we give two positions $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$, and we will tell you whether Little Horse can move from one position to the other one. All you need to do is construct a grid that meets all the conditions.

Input

The first line of the input contains an integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases.

The first line of each test case contains three integers $$$n,m,k$$$ ($$$1 \le n \times m \le 10^5$$$, $$$n \times m$$$ is even, $$$1 \le k \le 10^5$$$) — the number of rows and columns of the grid, and the number of conditions. The sum of $$$n \times m$$$ and the sum of $$$k$$$ will not exceed $$$2\times10^5$$$.

Then in the next $$$k$$$ lines, each line contains five integers $$$x_1,y_1,x_2,y_2,c$$$ ($$$1 \le x_1,x_2 \le n$$$, $$$1 \le y_1,y_2 \le m$$$, $$$0 \le c \le 1$$$).

  • $$$c=0$$$: Little Horse is unable to move from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$.
  • $$$c=1$$$: Little Horse is able to move from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$.
Output

For the $$$x$$$-th test case, if there's no possible solution, output $$$Case$$$ #$$$x$$$: $$$No$$$ in a single line.

Otherwise, output $$$Case$$$ #$$$x$$$: $$$Yes$$$ in a single line, and then output $$$n$$$ lines. Each line is a string of length $$$m$$$ which contains only $$$L$$$, $$$R$$$, $$$D$$$, $$$U$$$. For the $$$y$$$-th character in the $$$x$$$-th line:

  • $$$L$$$: $$$(x,y)$$$ shares the same color with $$$(x,y-1)$$$.
  • $$$R$$$: $$$(x,y)$$$ shares the same color with $$$(x,y+1)$$$.
  • $$$D$$$: $$$(x,y)$$$ shares the same color with $$$(x+1,y)$$$.
  • $$$U$$$: $$$(x,y)$$$ shares the same color with $$$(x-1,y)$$$.

If there are multiple solutions, output any.

ExampleInput
4
2 2 1
1 1 1 2 1
2 2 1
1 1 2 1 1
2 2 1
1 1 2 2 1
2 2 2
1 1 1 2 0
1 1 2 1 0
Output
Case #1: Yes
DD
UU
Case #2: Yes
RL
RL
Case #3: No
Case #4: No

加入题单

算法标签: