P23163 [AtCoder] Grid and Integers
提高+
题目描述

Problem Description

There is a grid with $ R $ rows and $ C $ columns. The cell located in the $ r $-th row from the top and the $ c $-th column from the left is called $ (r, c) $.

Takahashi wrote non-negative integers in $ N $ cells. Specifically, for each $1 \leq i \leq N$, he wrote a non-negative integer $ a_i $ in cell $ (r_i, c_i) $. After that, Takahashi started dozing off.

Aoki, who found the grid, wants to surprise Takahashi by filling in the remaining cells with integers. To surprise Takahashi, the grid must satisfy the following conditions:

  • Condition 1: Each cell contains a non-negative integer.
  • Condition 2: For any 2x2 square in the grid, the equation $ (top-left integer) + (bottom-right integer) = (top-right integer) + (bottom-left integer) $ always holds.

Determine whether it is possible to fill in the remaining cells with integers such that the grid satisfies these conditions.

Input Format

The input is given from the standard input in the following format:

$ R $ $ C $ $ N $ $ r_1 $ $ c_1 $ $ a_1 $ $ r_2 $ $ c_2 $ $ a_2 $ $ : $ $ r_N $ $ c_N $ $ a_N $

Output Format

If it is possible to fill in the remaining cells with integers such that the grid satisfies the conditions, output Yes. Otherwise, output No.

Sample Input and Output

Sample Input #1

2 2
3
1 1 0
1 2 10
2 1 20

Sample Output #1

Yes

Sample Input #2

2 3
5
1 1 0
1 2 10
1 3 20
2 1 30
2 3 40

Sample Output #2

No

Sample Input #3

2 2
3
1 1 20
1 2 10
2 1 0

Sample Output #3

No

Sample Input #4

3 3
4
1 1 0
1 3 10
3 1 10
3 3 20

Sample Output #4

Yes

Sample Input #5

2 2
4
1 1 0
1 2 10
2 1 30
2 2 20

Sample Output #5

No

Notes/Hints

Constraints

  • $2 \leq R, C \leq 10^5$
  • $1 \leq N \leq 10^5$
  • $1 \leq r_i \leq R$
  • $1 \leq c_i \leq C$
  • All $ (r_i, c_i) $ are distinct.
  • $ a_i $ is an integer.
  • $0 \leq a_i \leq 10^9$

Sample Explanation 1

You can fill in the integers as shown in the figure. [MATH0]

Sample Explanation 3

For condition 2 to hold, the empty cell must be -10. This violates condition 1. [MATH1]

Sample Explanation 5

All cells are already filled with integers, and condition 2 does not hold. ![](/img/other/code_festival_2016_quala/gbanjthabot/D_4.png)

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 3 1 1 0 1 2 10 2 1 20
样例输出
Yes