Language: C++

#include<iostream>
#include<vector>
using namespace std;

int main(void){
    int R;
    int C;
    int N;
    string res = "Yes";
    // input
    cin >> R;
    cin >> C;
    cin >> N;
    
    for (i=1; i<=N; i++) {
        cin >> r[i-1];
        cin >> c[i-1];
        cin >> a[i-1];
    } 
    
    //initialize
    vector<int> rr(N);
    vector<int> cc(N);
    vector<int> aa(N);
    vector<int> rca_flag(N, 1);
    vector<int> r_vec(R, 0);
    vector<int> c_vec(C, 0);
    vector<int> r_vec_flag(R, 0);
    vector<int> c_vec_flag(C, 0);
    int go_flg = 1;
    
    
    
    while (go_flg == 1){
        // find first
        for (int i=1; i<=N; i++){
            if (rca_flag[i-1] == 1){
                // initailize
                rca_flag[i-1] = 0;
                r = rr[i-1];
                c = cc[i-1];
                a = aa[i-1];
                r_vec[i-1] = a;
                r_vec_flag[r-1] = 1;
                c_vec[i-1] = 0;
                c_vec_flag[c-1] = 1;
                break;
            }
            if (i == N){
                go_flg = 0;
            }             
        }
        while (go_flg == 1){
            for (int i=1; i<=N; i++){
                if (rca_flag[i-1] == 1){
                    rca_flag[i-1] = 0;
                    r = rr[i-1];
                    c = cc[i-1];
                    a = aa[i-1];
                    if ((r_vec_flag[r-1] == 1) && (c_vec_flag[c-1] == 1)){
                        if (a != r_vec[r-1] + c_vec[c-1]){
                            res = "No";
                            go_flg = 0;
                        }
                    } else if (r_vec_flag[r-1] == 1){
                        c_vec_flag[c-1] = 1;
                        c_vec[c-1] = a - r_vec[r-1];
                    } else if (c_vec_flag[c-1] == 1){
                        r_vec_flag[r-1] = 1;
                        r_vec[r-1] = a - c_vec[c-1];
                    } 
                }
            }
        }
    }
    

    cout << res << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:10: error: 'i' was not declared in this scope
   15 |     for (i=1; i<=N; i++) {
      |          ^
a.cc:16:16: error: 'r' was not declared in this scope
   16 |         cin >> r[i-1];
      |                ^
a.cc:17:16: error: 'c' was not declared in this scope
   17 |         cin >> c[i-1];
      |                ^
a.cc:18:16: error: 'a' was not declared in this scope
   18 |         cin >> a[i-1];
      |                ^
a.cc:40:17: error: 'r' was not declared in this scope
   40 |                 r = rr[i-1];
      |                 ^
a.cc:41:17: error: 'c' was not declared in this scope
   41 |                 c = cc[i-1];
      |                 ^
a.cc:42:17: error: 'a' was not declared in this scope
   42 |                 a = aa[i-1];
      |                 ^
a.cc:57:21: error: 'r' was not declared in this scope
   57 |                     r = rr[i-1];
      |                     ^
a.cc:58:21: error: 'c' was not declared in this scope
   58 |                     c = cc[i-1];
      |                     ^
a.cc:59:21: error: 'a' was not declared in this scope
   59 |                     a = aa[i-1];
      |                     ^