#K8016. Adjacent Trees in a 2x2 Subgrid
Adjacent Trees in a 2x2 Subgrid
Adjacent Trees in a 2x2 Subgrid
You are given a grid of size \(n \times m\) and \(k\) trees located at distinct coordinates. Each tree is positioned at \( (r, c) \) with \(1 \le r \le n\) and \(1 \le c \le m\). Your task is to determine whether there exists any 2x2 subgrid that contains at least two adjacent trees (i.e. two trees that share a common edge within the subgrid).
In other words, consider any subgrid defined by cells \((i,j)\), \((i,j+1)\), \((i+1,j)\), and \((i+1,j+1)\) for some valid \(i\) and \(j\). The answer is "YES" if at least one of the following conditions is true for that subgrid:
- The cells \((i,j)\) and \((i,j+1)\) both contain trees.
- The cells \((i,j)\) and \((i+1,j)\) both contain trees.
- The cells \((i+1,j)\) and \((i+1,j+1)\) both contain trees.
- The cells \((i,j+1)\) and \((i+1,j+1)\) both contain trees.
Note: The intended solution checks for particular adjacent pairs by iterating through each tree and examining three specific neighbor patterns. Follow that logic in your implementation.
inputFormat
The first line of input contains three integers \(n\), \(m\), and \(k\) separated by spaces.
The following \(k\) lines each contain two integers \(r\) and \(c\), indicating the row and column of a tree.
You should read from standard input.
outputFormat
Output a single line containing either "YES" if there exists a 2x2 subgrid where at least two adjacent cells (sharing a common edge) both contain trees, or "NO" otherwise. Write the result to standard output.
## sample5 5 4
1 1
2 2
3 3
1 3
NO