题目描述
Problem Description
The Takahashi Kingdom consists of $N$ states numbered from $1$ to $N$.
The map of the Takahashi Kingdom is in the shape of a grid with $H$ rows and $W$ columns, where the cell at the $i$-th row and $j$-th column represents state $A_{i,j}$.
When coloring state $i$ with color $C_i$, are the following conditions satisfied?
If different states are adjacent to each other vertically or horizontally, they are painted in different colors.
Input Format
The input is given from the standard input in the following format:
$ H $ $ W $ $ N $ $ A_{1,1} $ $ A_{1,2} $ $\ldots$ $ A_{1,W} $ $ A_{2,1} $ $ A_{2,2} $ $\ldots$ $ A_{2,W} $ $\vdots$ $ A_{H,1} $ $ A_{H,2} $ $\ldots$ $ A_{H,W} $ $ C_1 $ $ C_2 $ $\ldots$ $ C_N $
Output Format
Output Yes if the conditions are satisfied, otherwise output No.
Sample Input and Output
Sample Input #1
2 4 3
1 1 2 3
1 2 2 3
2 3 3
Sample Output #1
No
Sample Input #2
3 5 4
1 1 1 3 2
1 2 1 3 4
1 1 1 3 2
3 1 4 3
Sample Output #2
Yes
Sample Input #3
2 2 3
1 2
3 1
1 2 2
Sample Output #3
Yes
Notes/Hints
Constraints
- $1\ \leq\ H\ \leq\ 200$
- $1\ \leq\ W\ \leq\ 200$
- $1\leq\ N\ \leq\ \min(100,H\times\ W)$
- $1\leq\ A_{i,j}\ \leq\ N$
- For every $k(1\leq\ k\leq\ N)$, there exists at least one pair $(i,j)$ such that $ A_{i,j}=k $
- $1\leq\ C_i\ \leq\ N$
- All values in the input are integers.
Sample Explanation 1
States $2$ and $3$ are adjacent but painted in the same color, so the condition is not satisfied. 
Sample Explanation 2
There may be cases like state $1$ where there are holes. Also, there may be cases like state $2$ where the states are not connected.
Sample Explanation 3
States $2$ and $3$ are not adjacent vertically or horizontally, so they can be painted in the same color and still satisfy the condition.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分