#K73842. Watering the Garden: Connectivity Check

    ID: 34065 Type: Default 1000ms 256MiB

Watering the Garden: Connectivity Check

Watering the Garden: Connectivity Check

In a garden represented as an \(N \times M\) grid, some sections are blocked and cannot be watered. Jessica wants to water every unblocked (manageable) section exactly once. In other words, starting from any unblocked cell, she must be able to reach every other unblocked cell by moving only in the four cardinal directions (up, down, left, right). Your task is to determine whether the unblocked cells form a connected region.

The garden is modeled as a grid where:

  • \(N\) is the number of rows.
  • \(M\) is the number of columns.
  • \(K\) is the number of blocked cells.

If all unblocked cells are connected, output YES; otherwise output NO.

inputFormat

The input is read from stdin and has the following format:

N M K
x1 y1
x2 y2
... 
xK yK

where:

  • N and M are the number of rows and columns of the grid, respectively.
  • K is the number of blocked sections.
  • Each of the following K lines contains two integers \(x\) and \(y\) which denote the 1-indexed coordinates of a blocked cell.

outputFormat

The output should be written to stdout and consists of a single line containing either YES or NO.

YES indicates that all unblocked cells are connected, while NO indicates that there exists at least one unblocked cell that cannot be reached.

## sample
3 3 1
2 2
YES

</p>