Language: C++

#include <iostream>
#include <math.h>
#include <vector>
#include <utility>
 
using namespace std;
 
bool DFSUtil(int, vector<bool>);
 
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, 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:14: error: too many arguments to function 'bool DFSUtil(int, std::vector<bool>)'
   27 |   if(!DFSUtil(0, visited, g)){
      |       ~~~~~~~^~~~~~~~~~~~~~~
a.cc:8:6: note: declared here
    8 | bool DFSUtil(int, vector<bool>);
      |      ^~~~~~~
a.cc: In function 'bool DFSUtil(int, std::vector<bool>, std::vector<std::pair<int, int> >&)':
a.cc:37:27: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka '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 '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka '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 '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka '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;
      |               ^~~~