Language: C++

#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
#define INF 0x3f3f3f3f
#define MAXN 100000
#define LL long long
LL read(){ 
    LL f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
LL n,m,Min=1,Max=INF,val[MAXN+5],vis[MAXN+5];
struct edge{
	LL v,w;
	edge(){}
	edge(LL V,LL W){v=V,w=W;}
};
vector<edge> G[MAXN+5];
void DFS(LL x,LL u,LL fa,LL f){
	if(x<=0){
		if(f){
			printf("0\n");
			exit(0);
		}
		Min=max(Min,-x+1);
	}
	if(f) Max=min(Max,x);
	vis[u]=f+1,val[u]=x;
	LL v,w,siz=G[u].size();
	for(int i=0;i<siz;i++){
		v=G[u][i].v,w=G[u][i].w;
		if(v==fa) continue;
		if(vis[v]){
			if(vis[u]==vis[v]){
				if(val[u]+val[v]>w||(val[u]+val[v])%2!=w%2){
					printf("0\n");
					exit(0);
				}
				if(Min>1+(w-(val[u]+val[v]))/2||Max<1+(w-(val[u]+val[v]))/2){
					printf("0\n");
					exit(0);
				}
				Max=Min=1+(w-(val[u]+val[v]))/2;
			}else{
				if(val[u]+val[v]!=w){
					printf("0\n");
					exit(0);
				}
				if(val[v]<=0){
					if(vis[v]-1){
						printf("0\n");
						exit(0);
					}
					Min=max(Min,-val[v]+1);
				}
			}
			return ;
		}
		DFS(w-x,v,u,(f+1)%2);
	}
	return ;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		LL u=read(),v=read(),w=read();
		G[u].push_back(edge(v,w));
		G[v].push_back(edge(u,w));
	}
	DFS(1,1,-1,0);
	printf("%lld\n",max(0,Max-Min+1));
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:82:28: error: no matching function for call to 'max(int, long long int)'
   82 |         printf("%lld\n",max(0,Max-Min+1));
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/set:62,
                 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:82:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   82 |         printf("%lld\n",max(0,Max-Min+1));
      |                         ~~~^~~~~~~~~~~~~
/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,
                 from a.cc:11:
/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:82:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |         printf("%lld\n",max(0,Max-Min+1));
      |                         ~~~^~~~~~~~~~~~~