Coal Mine
Time limit0.5sMemory limit64 MB
Assign each unit square one of k coal types so that the cells of type i are point-symmetric about elevator i, or report that no such assignment exists.
- Level
Medium7 of 10
- Topics
- Implementation, Simulation, Math, Graph
- Solved
- No attempts yet
Problem
There was a strike at a coal mine in Bytesia recently. Angry miners destroyed all the mine's data. You were hired to recover some data on what types of coal were mined in different parts of the mine.
The company mines different coal types. The coal mine is a rectangular grid. Every unit square of the grid is an area that mines exactly one type of coal. On some midpoints of edges of the unit squares, there are elevators, one for each of the coal types being mined in the mine. As a coal mine must be a work of art, the set of unit squares where coal of type is mined at is symmetric with respect to the point where the elevator assigned to coal type is located.
You are given the dimensions of the coal mine, the number and the locations of the elevators. Your task is to determine a way of assigning unit squares to coal types so the above conditions are met, or to determine that such an assignment does not exist.
Input
The first line of input consists of one integer , the number of test cases. Then, test cases proceed, described in the following way.
The first line of each test case description consists of three integers , amd (, , ): the dimensions of the coal mine and the number of different coal types mined in the mine. The upper-left corner of the upper-left field of the mine has coordinates , and the lower-right corner of the lower-right field has coordinates .
Then the locations of elevators follow, each one being represented as a line containing the coordinates of the elevator , (, ). Exactly one of is an integer and the other one is a half of an integer, representing a point on a grid's unit square edge. The -th (-based) of the elevators is assigned to coal type .
Output
For each test case, you must first output a single line containg a word "YES" if there exists a proper assignment of coal types to all grid's unit squares, or "NO" if such an assignment does not exist. Additionally, if such an assignment exists, you must then output lines, each containg integers separated by spaces. The -th number in the -th (-based) line must be an integer describing the coal type mined at square with upper-left coordinate of and lower-right of (). Coal types are denoted by integers from to . If there are several possible answers, print any one of them.