Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

typedef struct{
  int from,to,cost;
}edge;
const int V_MAX = 2510,E_MAX = 5010;
int V,E;
ll P;
vector<edge>es(E_MAX);
vector<vector<int> >G(V_MAX);
vector<bool> canmove(V_MAX,false);
vector<ll> d(V_MAX,MAX_I);

//ゴールまで行ける場所
int dfs(int g){
  if(canmove[g]) return 0;
  canmove[g] = true;
  for(const int & e : G[g]){
    dfs(e);
  }
  return 0;
}

int bellmanford(int s){
  rep(i,V)d[i] = MAX_I;
  d[s] = 0;
  if(!canmove[s]) return 0;
  while(true){
    bool update = false;
    for(const edge &e : es){
      if(!canmove[e.from])continue;
      if(d[e.from] != MAX_I && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from]+e.cost;
        update = true;
      }o
    }
    if(!update)break;
  }
  return 1;
}

bool find_negative_loop(){
  rep(i,V)d[i] = 0;
  rep(i,V){
    for(const edge &e : es){
      if(!canmove[e.to])continue;
      if(d[e.from] != MAX_I && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from]+e.cost;
        if(i==V-1)return true;
      }
    }
  }
  return false;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V >> E >> P;
  rep(i,E){
    ll A,B,C;cin >> A >> B >> C;
    --A;--B;
    es.push_back({A,B,P-C});
    G[B].push_back(A);
  }
  dfs(V-1);
  if(find_negative_loop()){
    cout << -1 << endl;
    return 0;
  }
  bellmanford(0);
  cout << max(0,-d[V-1]) << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int bellmanford(int)':
a.cc:64:8: error: 'o' was not declared in this scope
   64 |       }o
      |        ^
a.cc: In function 'int main()':
a.cc:92:19: warning: narrowing conversion of 'A' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   92 |     es.push_back({A,B,P-C});
      |                   ^
a.cc:92:21: warning: narrowing conversion of 'B' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   92 |     es.push_back({A,B,P-C});
      |                     ^
a.cc:92:24: warning: narrowing conversion of '(P - C)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   92 |     es.push_back({A,B,P-C});
      |                       ~^~
a.cc:101:14: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  101 |   cout << max(0,-d[V-1]) << 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:101:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  101 |   cout << max(0,-d[V-1]) << 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 'int'
  101 |   cout << max(0,-d[V-1]) << endl;
      |           ~~~^~~~~~~~~~~