Language: C++

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(j,n) for(int j = 0; j < (int)(n); ++j)
#define int ll
using pii = pair<int, int>;

int h, w;
int n;


const int INF = 1e18;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while (cin >> h >> w >> n) {

        bool yes = true;

        vector<vector<pii>> hols(h, {}), vers(w, {});
        vector<int> hol_min(h, INF), ver_min(w, INF);

        for (int i = 0; i < n; i++) {
            int ii, jj, a;
            cin >> ii >> jj;
            --ii; --jj;
            cin >> a;
            hols[ii].emplace_back(jj, a);
            vers[jj].emplace_back(ii, a);

            hol_min[ii] = min(hol_min[ii], a);
            ver_min[jj] = min(ver_min[jj], a);
        }


        
        vector<tuple<int, int, int>> hol_diff, ver_diff;
        
        for (int i = 0; i < h; i++) {
            sort(hols[i].begin(), hols[i].end());
        }
        for (auto &hol : hols) {
            for (int i = 0; i < (int)hol.size() - 1; i++) {
                int j1 = hol[i].first;
                int j2 = hol[i + 1].first;
                int d = hol[i + 1].second - hol[i].second;
                hol_diff.emplace_back(j1, j2, d);
            }
        }

        for (int j = 0; j < w; j++) {
            sort(vers[j].begin(), vers[j].end());
        }
        for (auto &ver : vers) {
            for (int j = 0; j < (int)ver.size() - 1; j++) {
                int i1 = ver[j].first;
                int i2 = ver[j + 1].first;
                int d = ver[j + 1].second - ver[j].second;
                ver_diff.emplace_back(i1, i2, d);
            }
        }

        sort(hol_diff.begin(), hol_diff.end());
        sort(ver_diff.begin(), ver_diff.end());

        vector<int> hol_rel(w + 1, -1);
        for (auto &t : hol_diff) {
            if (!yes) break;
            
            int j1, j2, d;
            tie(j1, j2, d) = t;
            
            assert(ver_min[j1] != INF);
            assert(ver_min[j2] != INF);

            if (hol_rel[j1] == -1) {
                hol_rel[j1] = ver_min[j1];
                hol_rel[j2] = hol_rel[j1] + d;
            } 
            if (hol_rel[j2] == -1) {
                hol_rel[j2] = hol_rel[j1] + d;
            }
            if (hol_rel[j1] + d != hol_rel[j2] || hol_rel[j1] < 0 || hol_rel[j2] < 0) {
                yes = false;
            }
        }

        vector<int> ver_rel(h + 1, -1);
        for (auto &t : hol_diff) {
            if (!yes) break;

            int i1, i2, d;
            tie(i1, i2, d) = t;

            assert(hol_min[i1] != INF);
            assert(hol_min[i2] != INF);

            if (ver_rel[i1] == -1) {
                ver_rel[i1] = hol_min[i1];
                ver_rel[i1] = ver_rel[i1] + d;
            }
            if (ver_rel[i2] == -1) {
                ver_rel[i2] = ver_rel[i1] + d;
            }
            if (ver_rel[i1] + d != ver_rel[i2] || ver_rel[i1] < 0 || ver_rel[i2] < 0) {
                yes = false;
            }
        }

        cout << (yes ? "Yes" : "No") << endl;
    }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:39: error: call of overloaded 'vector(ll&, <brace-enclosed initializer list>)' is ambiguous
   55 |         vector<vector<pii>> hols(h, {}), vers(w, {});
      |                                       ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:11:
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; size_type = long unsigned int; value_type = std::vector<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int> > >]'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; size_type = long unsigned int; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int> > >]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
a.cc:55:52: error: call of overloaded 'vector(ll&, <brace-enclosed initializer list>)' is ambiguous
   55 |         vector<vector<pii>> hols(h, {}), vers(w, {});
      |                                                    ^
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; size_type = long unsigned int; value_type = std::vector<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int> > >]'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; size_type = long unsigned int; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int> > >]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~