Language: C++

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int H, W, N;
  vector< pair< int, int > > g[200000];
  bool v[200000] = {};
  int64 cost[200000];

  scanf("%d %d", &H, &W);
  scanf("%d", &N);
  while(N--) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    --x, --y;
    g[x].emplace_back(H + y, z);
    g[H + y].emplace_back(x, z);
  }

  for(int i = 0; i < H + W; i++) {
    if(v[i]) continue;

    queue< int > que;
    int L = INF, R = INF;
    que.emplace(i);
    v[i] = true;
    cost[i] = 0;

    while(!que.empty()) {
      int idx = que.front();
      que.pop();
      if(idx < H) L = min(L, cost[idx]);
      else R = min(R, cost[idx]);
      for(auto& e : g[idx]) {
        if(v[e.first]++) {
          if(cost[idx] + cost[e.first] != e.second) {
            puts("No");
            return (0);
          }
        } else {
          que.emplace(e.first);
          cost[e.first] = e.second - cost[idx];
        }
      }
    }
    if(L + R < 0) {
      puts("No");
      return (0);
    }
  }

  puts("Yes");
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:13: warning: overflow in conversion from 'long long int' to 'int' changes value from '288230376151711744' to '0' [-Woverflow]
   29 |     int L = INF, R = INF;
      |             ^~~
a.cc:29:22: warning: overflow in conversion from 'long long int' to 'int' changes value from '288230376151711744' to '0' [-Woverflow]
   29 |     int L = INF, R = INF;
      |                      ^~~
a.cc:37:26: error: no matching function for call to 'min(int&, int64&)'
   37 |       if(idx < H) L = min(L, cost[idx]);
      |                       ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:37:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int64' {aka 'long long int'})
   37 |       if(idx < H) L = min(L, cost[idx]);
      |                       ~~~^~~~~~~~~~~~~~
/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:
/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:37:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |       if(idx < H) L = min(L, cost[idx]);
      |                       ~~~^~~~~~~~~~~~~~
a.cc:38:19: error: no matching function for call to 'min(int&, int64&)'
   38 |       else R = min(R, cost[idx]);
      |                ~~~^~~~~~~~~~~~~~
/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:38:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int64' {aka 'long long int'})
   38 |       else R = min(R, cost[idx]);
      |                ~~~^~~~~~~~~~~~~~
/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:38:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   38 |       else R = min(R, cost[idx]);
      |                ~~~^~~~~~~~~~~~~~
a.cc:40:21: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   40 |         if(v[e.first]++) {
      |            ~~~~~~~~~^