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;

using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<int>dist;
#define INF 1e18
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;
    

}


   

int main(){
    ll 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)){
        ll x=dist[n-1];
          dist=vector<ll>(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 'bool bellman_ford(int, int)':
a.cc:28:13: warning: overflow in conversion from 'double' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
   28 | #define INF 1e18
      |             ^~~~
a.cc:30:24: note: in expansion of macro 'INF'
   30 |     dist=vector<int>(n,INF);
      |                        ^~~
a.cc: In function 'int main()':
a.cc:75:32: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'std::vector<long long int>')
   75 |           dist=vector<ll>(n,INF);
      |                                ^
In file included from /usr/include/c++/14/vector:72,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:101:14: error: no matching function for call to 'max(ll, int)'
  101 |     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:
/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:101:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  101 |     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:101:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  101 |     cout<<max(-x,0)<<endl;
      |           ~~~^~~~~~