CF1844E.Great Grids

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

An n×mn \times m grid of characters is called great if it satisfies these three conditions:

  • Each character is either 'A', 'B', or 'C'.
  • Every 2×22 \times 2 contiguous subgrid contains all three different letters.
  • Any two cells that share a common edge contain different letters.

Let (x,y)(x,y) denote the cell in the xx -th row from the top and yy -th column from the left.

You want to construct a great grid that satisfies kk constraints. Each constraint consists of two cells, (xi,1,yi,1)(x_{i,1},y_{i,1}) and (xi,2,yi,2)(x_{i,2},y_{i,2}) , that share exactly one corner. You want your great grid to have the same letter in cells (xi,1,yi,1)(x_{i,1},y_{i,1}) and (xi,2,yi,2)(x_{i,2},y_{i,2}) .

Determine whether there exists a great grid satisfying all the constraints.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1031 \le t \le 10^3 ). The description of the test cases follows.

The first line of each test case contains three integers, nn , mm , and kk ( 2n,m21032 \le n,m \le 2 \cdot 10^3 , 1k41031 \le k \le 4 \cdot 10^3 ).

Each of the next kk lines contains four integers, xi,1x_{i,1} , yi,1y_{i,1} , xi,2x_{i,2} , and yi,2y_{i,2} ( 1xi,1<xi,2n1 \le x_{i,1} < x_{i,2} \le n , 1yi,1,yi,2m1 \le y_{i,1},y_{i,2} \le m ). It is guaranteed that either (xi,2,yi,2)=(xi,1+1,yi,1+1)(x_{i,2},y_{i,2}) = (x_{i,1}+1,y_{i,1}+1) or (xi,2,yi,2)=(xi,1+1,yi,11)(x_{i,2},y_{i,2}) = (x_{i,1}+1,y_{i,1}-1) .

The pairs of cells are pairwise distinct, i.e. for all 1i<jk1 \le i < j \le k , it is not true that xi,1=xj,1x_{i,1} = x_{j,1} , yi,1=yj,1y_{i,1} = y_{j,1} , xi,2=xj,2x_{i,2} = x_{j,2} , and yi,2=yj,2y_{i,2} = y_{j,2} .

It is guaranteed that the sum of nn over all test cases does not exceed 21032 \cdot 10^3 .

It is guaranteed that the sum of mm over all test cases does not exceed 21032 \cdot 10^3 .

It is guaranteed that the sum of kk over all test cases does not exceed 41034 \cdot 10^3 .

输出格式

For each test case, output "YES" if a great grid satisfying all the constraints exists and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

输入输出样例

  • 输入#1

    4
    3 4 4
    1 1 2 2
    2 1 3 2
    1 4 2 3
    2 3 3 2
    2 7 2
    1 1 2 2
    1 2 2 1
    8 5 4
    1 2 2 1
    1 5 2 4
    7 1 8 2
    7 4 8 5
    8 5 4
    1 2 2 1
    1 5 2 4
    7 1 8 2
    7 5 8 4

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, the following great grid satisfies all the constraints:

BABCCBCAACABIn the second test case, the two constraints imply that cells (1,1)(1,1) and (2,2)(2,2) have the same letter and cells (1,2)(1,2) and (2,1)(2,1) have the same letter, which makes it impossible for the only 2×22 \times 2 subgrid to contain all three different letters.

首页