Language: C++

#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

const long long MAX = 1e17;
using namespace std;

struct Edge {
	int to;
	int cost;
};






bool saiki(int now, long long num, bool istate, pair<long long, long long> &minpair) {
	if (istate) {
		if (tated[now]) {
			if (tate[now] != num) {
				return false;
			}
			return true;
		}
		tated[now] = true, tate[now] = num;
		minpair.first = min(minpair.first, num);
		for (auto &t : tateedge[now]) {
			if (!saiki(t.to, t.cost - num, false, minpair))
				return false;
		}
		return true;
	}
	else {
		if (yokod[now]) {
			if (yoko[now] != num) {
				return false;
			}
			return true;
		}
		yokod[now] = true, yoko[now] = num;
		minpair.second = min(minpair.second, num);
		for (auto &t : yokoedge[now]) {
			if (!saiki(t.to, t.cost - num, true, minpair))
				return false;
		}
		return true;

	}
}


int main() {
	int R, C;
	cin >> R >> C;
	int N;
	cin >> N;
	vector<int> r(N), c(N), a(N);
	for (int i = 0; i < N; i++) {
		cin >> r[i] >> c[i] >> a[i];
		r[i]--, c[i]--;
	}

	vector<vector<Edge>> tateedge, yokoedge;
	vector<long long> tate, yoko;
	vector<bool> tated, yokod;
	tateedge.resize(R);
	yokoedge.resize(C);
	tate.resize(R);
	yoko.resize(R);
	tated.resize(R, false);
	yokod.resize(C, false);


	for (int i = 0; i < N; i++) {
		tateedge[r[i]].push_back({ c[i], a[i] });
		yokoedge[c[i]].push_back({ r[i], a[i] });
	}
	bool res = true;
	for (int i = 0; i < R; i++) {
		pair<long long, long long> minp{ MAX,MAX };
		if (tated[i] || tateedge[i].empty())
			continue;
		if (!saiki(i, -100, true, minp)) {
			res = false;
			break;
		}
		if (minp.first + minp.second < 0) {
			res = false;
			break;
		}
	}
	cout << (res ? "Yes" : "No") << endl;

	return 0;
}


Compiler output:
a.cc: In function 'bool saiki(int, long long int, bool, std::pair<long long int, long long int>&)':
a.cc:40:21: error: 'tated' was not declared in this scope
   40 |                 if (tated[now]) {
      |                     ^~~~~
a.cc:41:29: error: 'tate' was not declared in this scope; did you mean 'istate'?
   41 |                         if (tate[now] != num) {
      |                             ^~~~
      |                             istate
a.cc:46:17: error: 'tated' was not declared in this scope
   46 |                 tated[now] = true, tate[now] = num;
      |                 ^~~~~
a.cc:46:36: error: 'tate' was not declared in this scope; did you mean 'istate'?
   46 |                 tated[now] = true, tate[now] = num;
      |                                    ^~~~
      |                                    istate
a.cc:48:32: error: 'tateedge' was not declared in this scope
   48 |                 for (auto &t : tateedge[now]) {
      |                                ^~~~~~~~
a.cc:55:21: error: 'yokod' was not declared in this scope
   55 |                 if (yokod[now]) {
      |                     ^~~~~
a.cc:56:29: error: 'yoko' was not declared in this scope
   56 |                         if (yoko[now] != num) {
      |                             ^~~~
a.cc:61:17: error: 'yokod' was not declared in this scope
   61 |                 yokod[now] = true, yoko[now] = num;
      |                 ^~~~~
a.cc:61:36: error: 'yoko' was not declared in this scope
   61 |                 yokod[now] = true, yoko[now] = num;
      |                                    ^~~~
a.cc:63:32: error: 'yokoedge' was not declared in this scope
   63 |                 for (auto &t : yokoedge[now]) {
      |                                ^~~~~~~~