Language: C++

#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int;

#define int long long
const int INF = 100000000000000000;

const int MAX_N = 100005;
const int MAX_M = 100005;

int N, M;
struct Edge {
    int to, s;
};

vector<Edge> edgeList[MAX_N];

int C[MAX_N];

int solve(int pos, int f, int sum = 0)
{
    if(C[pos] == 0) {
        C[pos] = f;
    } else if(C[pos] == f) {
        return 0;
    } else {
        return sum;
    }
    
    int nextF = f * -1;
    for(int i = 0; i < edgeList[pos].size(); i++) {
        Edge edge = edgeList[pos][i];
        int ret;
        if(f > 0) {
           ret = solve(edge.to, nextF, sum + edge.s);
        } else {
            ret = solve(edge.to, nextF, sum - edge.s);
        }
         
        if(ret != 0) {
            return ret;
        }
    }

    return 0;
}

int Check[MAX_N];
bool check(int pos, int x)
{
    Check[pos] = x;
    bool ret = true;
    for(int i = 0; i < edgeList[pos].size(); i++) {
        Edge nextEdge = edgeList[pos][i];
        int nextC = nextEdge.s - x;
        if(nextC >= 1) {
            if(Check[nextEdge.to] == 0) {
                ret &= check(nextEdge.to, nextC);
            } else if(Check[nextEdge.to] != nextC) {
                return false;
            }
        } else {
            return false;
        }
    }

    return ret;
}

bool used[MAX_N];
int Sum[MAX_N];
bool ansFlag = true;

void calcSum(int pos, int s)
{
    used[pos] = true;
    Sum[pos] = s;
    for(int i = 0; i < edgeList[pos].size(); i++) {
        Edge edge = edgeList[pos][i];
        int nextS = edge.s - s;
        if(used[edge.to]) {
            if(Sum[edge.to] != nextS) {
                ansFlag = false;
                return;
            }
            continue;
        }
        calcSum(edge.to, nextS);
    }
}

signed main()
{
    cin >> N >> M;
    for(int i =0; i < M; i++) {
        int u, v, s;
        cin >> u >> v >> s;
        u--; v--;
        Edge edge; edge.to = v; edge.s = s;
        edgeList[u].push_back(edge);
        edge.to = u;
        edgeList[v].push_back(edge);
    }

    int S = solve(0, 1);

    if(S != 0) { //奇数ループ発見
        int x = S/2;
        if(check(0, x)) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return 0;
    }

    calcSum(0, 0);
    if(!ansFlag) {
        cout << 0 << endl;
        return 0;
    }

    int AA = 114514191981036436, BB = 114514191981034636;
    for(int i = 0; i < N; i++) {
        // cerr << i << " " << Sum[i] << endl;
        if(C[i] > 0) {
            AA = min(AA, Sum[i]);
        } else {
            BB = min(BB, Sum[i]);
        }
    }

    // cerr << AA << " " << BB << endl;

    AA = -1*AA + 1;
    BB--;

    int ans = 0;

    if(AA <= BB) {
        ans + =BB-AA+1;
    } else {
    }

int AA = -114514191981036436, BB = -114514191981034636;
    for(int i = 0; i < N; i++) {
        // cerr << i << " " << Sum[i] << endl;
        if(C[i] > 0) {
            AA = max(AA, Sum[i]);
        } else {
            BB = max(BB, Sum[i]);
        }
    }

    // cerr << AA << " " << BB << endl;

    AA = -1*AA + 1;
    BB--;

    if(AA <= BB) {
        ans + =BB-AA+1;
    } else {
    }

    cout << ans << endl;



    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:142:15: error: expected primary-expression before '=' token
  142 |         ans + =BB-AA+1;
      |               ^
a.cc:146:5: error: redeclaration of 'long long int AA'
  146 | int AA = -114514191981036436, BB = -114514191981034636;
      |     ^~
a.cc:124:9: note: 'long long int AA' previously declared here
  124 |     int AA = 114514191981036436, BB = 114514191981034636;
      |         ^~
a.cc:146:31: error: redeclaration of 'long long int BB'
  146 | int AA = -114514191981036436, BB = -114514191981034636;
      |                               ^~
a.cc:124:34: note: 'long long int BB' previously declared here
  124 |     int AA = 114514191981036436, BB = 114514191981034636;
      |                                  ^~
a.cc:162:15: error: expected primary-expression before '=' token
  162 |         ans + =BB-AA+1;
      |               ^