Language: C++

#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
#define int lld
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<vector<pii>> G;
vector<int> gone;
vector<pii> res;// a+bx;
bool d = false; int X;
void dfs(int i){
    gone[i] = 1;
    for(auto x: G[i]){
        pii proc = {x.ss-res[i].ff, -res[i].ss};
        if(!gone[x.ff])res[x.ff] = proc, dfs(x.ff);
        else if(res[x.ff].ss == proc.ss){
            if(res[x.ff].ff != proc.ff)throw "wrong constraints";
        }else{
            int px = (proc.ss==1?1:-1)*(res[x.ff].ff-proc.ff);
            if(d && X*2 != px)throw ((string)"two constraints: " + to_string(X*2) + " " + to_string(px)).c_str();
            X = px/2, d = 1;
            if(X*2 != px)throw "not div 2";
        }
    }
}
signed main(){
    int n, m;
    cin >> n >> m;
    G.resize(n+1);gone.resize(n+1);res.resize(n+1);
    for(int i = 0; i < m; i++){
        int a, b, s;
        cin >> a >> b >> s;
        G[a].pb({b, s});
        G[b].pb({a, s});
    }
    res[1] = {0, 1};
    try{
        dfs(1);
        if(d){
            for(int i = 1; i <= n; i++){
                if(res[i].ss == 1){if(res[i].ff+X<=0)throw "constraint failed";}
                else{if(res[i].ff-X<=0)throw "constraint failed";}
            }
            cout << 1 << endl;
        }else{
            int mins = INT_MIN, maxs = INT_MAX;
            for(int i = 1; i <= n; i++){
                if(res[i].ss == 1)mins = max(mins, 1-res[i].ff);
                else maxs = min(maxs, res[i].ff-1);
            }

            cout << max(0LL, maxs-mins+1) << endl;
        }
    }catch(const char* s){
        cout << 0 << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:111:24: error: no matching function for call to 'max(long long int, lld)'
  111 |             cout << max(0LL, maxs-mins+1) << endl;
      |                     ~~~^~~~~~~~~~~~~~~~~~
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:3:
/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:111:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'lld' {aka 'long int'})
  111 |             cout << max(0LL, maxs-mins+1) << endl;
      |                     ~~~^~~~~~~~~~~~~~~~~~
/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:111:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  111 |             cout << max(0LL, maxs-mins+1) << endl;
      |                     ~~~^~~~~~~~~~~~~~~~~~