Language: C++

// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

#ifndef REP
#define REP(i,n) for (int i = 0; i < n; ++i)
#endif

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = false;
const int mmm = numeric_limits<int>::max();

// --------------------------------------------------------------------------------------

using namespace std;

bool propagate(int** a, int l, int r, int d) {
    if (a[l][r] == mmm) {
        a[l][r] = d;
        a[r][l] = -d;
        REP(i,n) {
            if (i == l || i == r) continue;
            int connect = a[i][r];
            if (connect == mmm) continue;
            // l + d == r
            // i + connect == r
            // l + d - connect == i
            if (!propagate(a, l, i, d - connect)) {
                return false;
            }
        }
    } else if (a[l][r] != d) {
        return false;
    }
    return true;
}

int main(void)
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    int** a = new int*[n];
    REP(i,n) { a[i] = new int[n]; REP(j,n) a[i][j] = mmm; }
    REP(i,n) { a[i][i] = 0; }
    REP(i,m) {
        int l, r, d;
        cin >> l >> r >> d;
        --l; --r;
        if (!propagate(a, l, r, d)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    REP(i,n) {
        delete[] a[i];
    }
    delete[] a;

    return 0;
}


Compiler output:
a.cc:58:17: error: 'numeric_limits' was not declared in this scope; did you mean 'std::numeric_limits'?
   58 | const int mmm = numeric_limits<int>::max();
      |                 ^~~~~~~~~~~~~~
      |                 std::numeric_limits
In file included from /usr/include/c++/14/bits/specfun.h:44,
                 from /usr/include/c++/14/cmath:3906,
                 from /usr/include/c++/14/valarray:39,
                 from a.cc:15:
/usr/include/c++/14/limits:312:12: note: 'std::numeric_limits' declared here
  312 |     struct numeric_limits : public __numeric_limits_base
      |            ^~~~~~~~~~~~~~
a.cc:58:32: error: expected primary-expression before 'int'
   58 | const int mmm = numeric_limits<int>::max();
      |                                ^~~
a.cc: In function 'bool propagate(int**, int, int, int)':
a.cc:68:15: error: 'n' was not declared in this scope
   68 |         REP(i,n) {
      |               ^
a.cc:33:38: note: in definition of macro 'REP'
   33 | #define REP(i,n) for (int i = 0; i < n; ++i)
      |                                      ^