#K80877. Path Existence in Grid

    ID: 35628 Type: Default 1000ms 256MiB

Path Existence in Grid

Path Existence in Grid

You are given a grid with dimensions \(N \times M\). The grid consists of cells that can either be empty or contain obstacles. You are also provided with a starting cell \((startX, startY)\) and a final target cell \((endX, endY)\). You can move in four directions: up, down, left, and right. However, cells containing obstacles cannot be traversed.

Your task is to determine whether there exists a path from the starting cell to the final cell without passing through any obstacles. For each test case, output YES if such a path exists, and NO otherwise.

Note: All coordinates are zero-indexed and movements are allowed only within the bounds \(0 \leq x < N\) and \(0 \leq y < M\).

inputFormat

The input begins with an integer \(T\), the number of test cases. For each test case, the input format is as follows:

  • A line with two integers \(N\) and \(M\), the number of rows and columns of the grid.
  • A line with two integers representing the starting cell: startX startY.
  • A line with two integers representing the final cell: endX endY.
  • A line with an integer \(K\) representing the number of obstacles.
  • \(K\) subsequent lines, each containing two integers corresponding to the coordinates of an obstacle.

All input is provided via standard input (stdin).

outputFormat

For each test case, print a single line containing either YES or NO via standard output (stdout). YES indicates that there exists a path from the starting cell to the final cell, and NO indicates that there is no such path.

## sample
3
5 5
0 0
4 4
3
0 1
1 0
1 2
5 5
0 0
4 4
0
2 2
0 0
1 1
3
0 1
1 0
1 1
NO

YES NO

</p>