Language: C++

#include <iostream>
#include <math.h>
#include <vector>
#include <utility>
 
using namespace std;
 
bool DFSUtil(int, vector<bool>, const vector<pair<int,int>>&);
 
int main(){
  int R, C;
  cin >> R >> C;
  int N;
  cin >> N;
  vector<pair<int, int>> g[C + R];
  
  for(int i = 0; i < N; i++){
    int r, c, a;
    cin >> r >> c >> a;
    g[r].push_back(make_pair( c + C, a));
    g[c + C].push_back(make_pair(r, a));
  }
 
  vector<bool> visited(R + C, false);
  vector<int> node(R + C, 0);
  int minR, minC = pow(10,9);
  if(!DFSUtil(0, visited, g)){
    cout << "No";
  }
  else{
    cout << "Yes";
  }
}
 
bool DFSUtil(int v, vector<bool> visited, const vector<pair<int,int>> &g){
  visited[v] = true;
  for(int i = 0; i < g[v].size(); i++){
    int w = g[v][i]. first;
    int a = g[v][i].second;
    if(visited[w] && node[v] + node[w] != a){
      return false;
    }
    node[w] = a - node[v];
 
    if(v < R) minR = minR >node[v] ? node[v] : minR;
    if(v >= R) minC = minC>node[v] ? node[v] : minC;
    if(minR + minC < 0) return false;
    if(!visited[w]){
      if(!DFSUtil(w, visited,g)) return false;
    }
  }
  return true;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:27: error: invalid initialization of reference of type 'const std::vector<std::pair<int, int> >&' from expression of type 'std::vector<std::pair<int, int> > [(C + R)]'
   27 |   if(!DFSUtil(0, visited, g)){
      |                           ^
a.cc:8:33: note: in passing argument 3 of 'bool DFSUtil(int, std::vector<bool>, const std::vector<std::pair<int, int> >&)'
    8 | bool DFSUtil(int, vector<bool>, const vector<pair<int,int>>&);
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'bool DFSUtil(int, std::vector<bool>, const std::vector<std::pair<int, int> >&)':
a.cc:37:27: error: 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'const struct std::pair<int, int>'} has no member named 'size'
   37 |   for(int i = 0; i < g[v].size(); i++){
      |                           ^~~~
a.cc:38:17: error: no match for 'operator[]' (operand types are 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'const std::pair<int, int>'} and 'int')
   38 |     int w = g[v][i]. first;
      |                 ^
a.cc:39:17: error: no match for 'operator[]' (operand types are 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'const std::pair<int, int>'} and 'int')
   39 |     int a = g[v][i].second;
      |                 ^
a.cc:40:22: error: 'node' was not declared in this scope
   40 |     if(visited[w] && node[v] + node[w] != a){
      |                      ^~~~
a.cc:43:5: error: 'node' was not declared in this scope
   43 |     node[w] = a - node[v];
      |     ^~~~
a.cc:45:12: error: 'R' was not declared in this scope
   45 |     if(v < R) minR = minR >node[v] ? node[v] : minR;
      |            ^
a.cc:45:15: error: 'minR' was not declared in this scope
   45 |     if(v < R) minR = minR >node[v] ? node[v] : minR;
      |               ^~~~
a.cc:46:13: error: 'R' was not declared in this scope
   46 |     if(v >= R) minC = minC>node[v] ? node[v] : minC;
      |             ^
a.cc:46:16: error: 'minC' was not declared in this scope
   46 |     if(v >= R) minC = minC>node[v] ? node[v] : minC;
      |                ^~~~
a.cc:47:8: error: 'minR' was not declared in this scope
   47 |     if(minR + minC < 0) return false;
      |        ^~~~
a.cc:47:15: error: 'minC' was not declared in this scope
   47 |     if(minR + minC < 0) return false;
      |               ^~~~