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 inf 100000000000000000
#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

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

vector<ll> row, col;
vector<vector<node>> GR, GC;

void dfs(node nd){
    int r = nd.r, c = nd.c;
    ll n = nd.n;
    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, 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]){
            if(row[nd.r] + col[nd.c] != nd.n){
                output("No");
                return 0;
            }
        }
    }
    
    
    int 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:
a.cc: In function 'int main()':
a.cc:18:13: warning: overflow in conversion from 'long int' to 'int' changes value from '100000000000000000' to '1569325056' [-Woverflow]
   18 | #define inf 100000000000000000
      |             ^~~~~~~~~~~~~~~~~~
a.cc:101:19: note: in expansion of macro 'inf'
  101 |     int row_min = inf, col_min = inf;
      |                   ^~~
a.cc:18:13: warning: overflow in conversion from 'long int' to 'int' changes value from '100000000000000000' to '1569325056' [-Woverflow]
   18 | #define inf 100000000000000000
      |             ^~~~~~~~~~~~~~~~~~
a.cc:101:34: note: in expansion of macro 'inf'
  101 |     int row_min = inf, col_min = inf;
      |                                  ^~~
a.cc:103:22: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  103 |         row_min = min(row_min, row[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:103:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  103 |         row_min = min(row_min, row[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:103:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  103 |         row_min = min(row_min, row[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~
a.cc:106:22: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  106 |         col_min = min(col_min, col[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:106:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  106 |         col_min = min(col_min, col[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:106:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  106 |         col_min = min(col_min, col[i]);
      |                   ~~~^~~~~~~~~~~~~~~~~