Language: C++

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

#define int long long
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<int>dist;
#define INF 1e9+7
bool bellman_ford(int n,int s){//nは頂点数 sは始点
    dist=vector<int>(n,INF);
    dist[s]=0;
    for (int i = 0; i < n; i++)
    {
        for (int v = 0; v < n; v++)
        {
            for (int k = 0; k < G[v].size(); k++)
            {
                Edge e=G[v][k];
                if(dist[v]!=INF && dist[e.first]>dist[v]+e.second){
                    dist[e.first]=dist[v]+e.second;
                    if(i == n-1)  return true; 
                            
                }
            }
            
        }
        }
        
    
    return false;
    

}

bool bellman_ford2(int n,int s){//nは頂点数 sは始点
    dist=vector<int>(n,INF);
    dist[s]=0;
    for (int i = 0; i < n; i++)
    {
        for (int v = 0; v < n; v++)
        {
            for (int k = 0; k < G[v].size(); k++)
            {
                Edge e=G[v][k];
                if(dist[v]!=INF && dist[e.first]>dist[v]+e.second){
                    dist[e.first]=dist[v]+e.second;
                    if(i == n-1) {
                        return true; 
                    }
                    }
                            
                }
            }

             return false;
        }
}

signed main(){
    int n,m,p;
    cin>>n>>m>>p;
    G.assign(n,vector<Edge>());
    for (int i = 0; i < m; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        G[a].push_back(Edge(b,(-1)*(c-p)));
    }

    bellman_ford(n, 0);
    //cerr<<bellman_ford(n, 0)<<endl;
    if(bellman_ford(n,0)){
        int x=dist[n-1];
          dist=vector<int>(n,INF);
    dist[0]=0;
    bool flag=true;
    for (int i = 0; i < n; i++)
    {
        for (int v = 0; v < n; v++)
        {
            for (int k = 0; k < G[v].size(); k++)
            {
                Edge e=G[v][k];
                if(dist[v]!=INF && dist[e.first]>=dist[v]+e.second){
                    dist[e.first]=dist[v]+e.second;
                    //cerr<<e.first<<dist[e.first]<<endl;
                    if(e.first == n-1 ){
                        if(dist[e.first] > x){
                            cout<<-1<<endl;
                            return 0;
                        } 
                    }
                   
                    }
                            
                }
            }
            
        }
    cout<<max(-x,0)<<endl; 
    return 0;       
}


    
       //show(dist);
    cout<<max(-dist[n-1],0)<<endl;
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:123:14: error: no matching function for call to 'max(long long int, int)'
  123 |     cout<<max(-x,0)<<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: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:123:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  123 |     cout<<max(-x,0)<<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:123:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  123 |     cout<<max(-x,0)<<endl;
      |           ~~~^~~~~~
a.cc:130:14: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
  130 |     cout<<max(-dist[n-1],0)<<endl;
      |           ~~~^~~~~~~~~~~~~~
/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:130:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  130 |     cout<<max(-dist[n-1],0)<<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
/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:130:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  130 |     cout<<max(-dist[n-1],0)<<endl;
      |           ~~~^~~~~~~~~~~~~~
a.cc: In function 'bool bellman_ford2(long long int, long long int)':
a.cc:78:1: warning: control reaches end of non-void function [-Wreturn-type]
   78 | }
      | ^