Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define N 5005
#define int long long
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,m,p;
int e_cnt=0,head[N];
int cnt[N],vis[N],dis[N],ok1[N],g[N][N],g2[N][N],ok2[N];
queue<int> q;
struct Edge{
	int to,nxt,val;
}edge[N<<2];
void add(int a,int b,int c){
	e_cnt++;
	edge[e_cnt].to=b;
	edge[e_cnt].nxt=head[a];
	edge[e_cnt].val=c;
	head[a]=e_cnt;
}
bool SPFA(int s){
	memset(dis,-0x3f,sizeof(dis));
	dis[s]=0;
	vis[s]=1;
	q.push(s);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(!(ok1[v]&&ok2[v]))continue;
			if(dis[v]<dis[u]+edge[i].val){
				dis[v]=dis[u]+edge[i].val;
				if(!vis[v]){
					cnt[v]++;
					vis[v]=1;
					q.push(v);
				}
				if(cnt[v]>n){
					return true;
				}
			}
		}
	}
	return false;
}
void dfs1(int u){
	for(int i=1;i<=n;i++){
		if(ok1[i]||i==u)continue;
		if(g[u][i]){
			ok1[i]=1;
			dfs1(i);
		}
	}
}
void dfs2(int u){
	for(int i=1;i<=n;i++){
		if(ok2[i]||i==u)continue;
		if(g2[u][i]){
			ok2[i]=1;
			dfs2(i);
		}
	}
}
signed main(){
	n=read(),m=read();p=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		add(u,v,w-p);
		g[u][v]=1;
		g2[v][u]=1;
	}
	ok1[1]=ok2[1]=ok1[n]=ok2[n]=1;
	dfs1(1);
	dfs2(n);
	if(SPFA(1)){
		cout<<-1<<endl;
	}
	else{
		cout<<max(0,dis[n])<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:96:26: error: no matching function for call to 'max(int, long long int&)'
   96 |                 cout<<max(0,dis[n])<<endl;
      |                       ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:96:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   96 |                 cout<<max(0,dis[n])<<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,
                 from a.cc:4:
/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:96:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   96 |                 cout<<max(0,dis[n])<<endl;
      |                       ~~~^~~~~~~~~~