CF1848A.Vika and Her Friends

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Vika and her friends went shopping in a mall, which can be represented as a rectangular grid of rooms with sides of length nn and mm . Each room has coordinates (a,b)(a, b) , where 1an,1bm1 \le a \le n, 1 \le b \le m . Thus we call a hall with coordinates (c,d)(c, d) a neighbouring for it if ac+bd=1|a - c| + |b - d| = 1 .

Tired of empty fashion talks, Vika decided to sneak away unnoticed. But since she hasn't had a chance to visit one of the shops yet, she doesn't want to leave the mall. After a while, her friends noticed Vika's disappearance and started looking for her.

Currently, Vika is in a room with coordinates (x,y)(x, y) , and her kk friends are in rooms with coordinates (x1,y1)(x_1, y_1) , (x2,y2)(x_2, y_2) , ... ,(xk,yk), (x_k, y_k) , respectively. The coordinates can coincide. Note that all the girls must move to the neighbouring rooms.

Every minute, first Vika moves to one of the adjacent to the side rooms of her choice, and then each friend (seeing Vika's choice) also chooses one of the adjacent rooms to move to.

If at the end of the minute (that is, after all the girls have moved on to the neighbouring rooms) at least one friend is in the same room as Vika, she is caught and all the other friends are called.

Tell us, can Vika run away from her annoying friends forever, or will she have to continue listening to empty fashion talks after some time?

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers nn , mm , kk ( 1n,m,k1001 \le n, m, k \le 100 ) — the sizes of the mall and the number of Vika's friends.

The second line of each test case contains a pair of integers xx and yy ( 1xn1 \le x \le n , 1ym1 \le y \le m ) — the coordinates of the room where Vika is.

Each of the next kk lines of each test case contains a pair of integers xix_i and yiy_i ( 1xin1 \le x_i \le n , 1yim1 \le y_i \le m ) — the coordinates of the room where the ii -th friend is.

输出格式

For each test case, output "YES" if Vika can run away from her friends forever, otherwise output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

输入输出样例

  • 输入#1

    6
    2 2 1
    1 1
    1 2
    2 2 2
    1 1
    2 2
    2 2
    1 2 1
    1 1
    1 2
    5 5 4
    3 3
    1 1
    1 5
    5 1
    5 5
    2 2 2
    1 1
    2 1
    1 2
    3 4 1
    1 2
    3 3

    输出#1

    YES
    NO
    YES
    NO
    YES
    YES

说明/提示

In the first test case, the friend will never catch up with Vika, because Vika can always move to the room diagonally opposite to the one where the friend is.

In the second test case, no matter where Vika goes, each of her friends can catch her after the first move.

In the third test case, Vika and her friend will always be in different halls.

首页