Language: C++

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

const ll inf = 1LL << 60;

struct node{
    int r, c;
    ll n;
};

vector<ll> row, col;
map<node, int> M;
vector<vector<node>> GR, GC;

void dfs(node nd){
    int r = nd.r, c = nd.c;
    ll n = nd.n;
//    cout << r << "," << c << "," << n << endl;
//    cout << row[r] << "," << col[c] << endl;
    if(M[nd]) return;
    M[nd] = 1;
    if(row[r] == inf && col[c] == inf){
        row[r] = n, col[c] = 0;
    }
    else if(row[r] == inf){
        row[r] = n - col[c];
    }
    else if(col[c] == inf){
        col[c] = n - row[r];
    }
    else return;
    for(node nr: GR[r]){
        dfs(nr);
    }
    for(node nc: GC[c]){
        dfs(nc);
    }

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int R, C, N;
    cin >> R >> C >> N;
    row.resize(R + 1, inf), col.resize(C + 1, inf);
    GR.resize(R + 1), GC.resize(C + 1);
    
    rep(i, N){
        int r, c;
        ll a;
        cin >> r >> c >> a;
        GR[r].pb({r, c, a});
        GC[c].pb({r, c, a});
    }
    
    rep(i, R + 1){
        if(GR[i].size()){
            for(node nd: GR[i]){
                dfs(nd);
            }
        }
    }
    rep(i, C + 1){
        if(GC[i].size()){
            for(node nd: GC[i]){
                dfs(nd);
            }
        }
    }
    
    rep(i, R + 1){
        for(node nd: GR[i]){
//            cout << row[nd.r] << "," << col[nd.c] << "," << nd.n << endl;
            if(row[nd.r] + col[nd.c] != nd.n){
                output("No");
                return 0;
            }
        }
    }
    
    
    ll row_min = inf, col_min = inf;
    rep(i, R + 1){
        row_min = min(row_min, row[i]);
    }
    rep(i, C + 1){
        col_min = min(col_min, col[i]);
    }
    if(row_min + col_min < 0){
        output("No");
    }
    else{
        output("Yes");
    }
    
    
    
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = node]':
/usr/include/c++/14/bits/stl_map.h:511:32:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = node; _Tp = int; _Compare = std::less<node>; _Alloc = std::allocator<std::pair<const node, int> >; mapped_type = int; key_type = node]'
  511 |         if (__i == end() || key_comp()(__k, (*__i).first))
      |                             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:45:12:   required from here
   45 |     if(M[nd]) return;
      |            ^
/usr/include/c++/14/bits/stl_function.h:405:20: error: no match for 'operator<' (operand types are 'const node' and 'const node')
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const node' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const node' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const node' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const node' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~