Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

vector<pair<int, int>> G[100100];
vector<pair<int, int>> cond(100100, {0, 0});
int minv = 0, maxv = inf;

void dfs(int v, int res, int depth, int par) {
  if (depth & 1) {
    chmin(maxv, res);
    cond[v] = {-1, res};
  }
  else {
    chmax(minv, -res);
    cond[v] = {1, res};
  }
  if (maxv - minv <= 1) return;
  for (auto p: G[v]) {
    int u = p.first, x = p.second;
    if (u == par) continue;
    if (cond[u].first == 0) dfs(u, x - res, depth + 1, v);
    else {
      pair<int, int> rescond = {0, x - res};
      if ((depth + 1) & 1) rescond.first = -1;
      else rescond.second = 1;
      if (cond[u].first == rescond.first) {
        if (cond[u].second != rescond.second) {
          minv = inf;
          return;
        }
      }
      else {
        int tmp = 0;
        if (cond[u].first == -1) tmp += cond[u].second;
        else tmp -= cond[u].second;
        if (rescond.first == -1) tmp += rescond.second;
        else tmp -= rescond.second;
        if (tmp <= 0) {
          minv = inf;
          return;
        }
        if (tmp & 1) {
          minv = inf;
          return;
        }
        tmp /= 2;
        minv = tmp - 1;
        maxv = tmp + 1;
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int u, v, s;
    cin >> u >> v >> s;
    u--, v--;
    G[u].push_back({v, s});
    G[v].push_back({u, s});
  }

  dfs(0, 0, 0, -1);
  //rep(i, n) cout << cond[i].first << ' ' << cond[i].second << '\n';
  cout << max(0, maxv - minv - 1) << '\n';

  




  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:14: error: no matching function for call to 'max(int, long long int)'
   89 |   cout << max(0, maxv - minv - 1) << '\n';
      |           ~~~^~~~~~~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:89:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   89 |   cout << max(0, maxv - minv - 1) << '\n';
      |           ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:89:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   89 |   cout << max(0, maxv - minv - 1) << '\n';
      |           ~~~^~~~~~~~~~~~~~~~~~~~