Language: C++

#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

struct edge{int from,to,c;};

int main(){
    int MAX_V = 2510, MAX_E = 5020;
    int V,E,P; cin>>V>>E>>P;
    vector<edge> ed(MAX_E);
    vector<ll> p(MAX_V,INF);
    rep(i,E){cin>>ed[i].from>>ed[i].to>>ed[i].c; ed[i].c *= -1;}

    p[1] = 0;
    rep(i,V){
        rep(j,E){
            edge e = ed[j];
            if(p[e.from] != INF && p[e.to]> p[e.from]+e.c+P){
                p[e.to] = p[e.from]+e.c+P;
            }
        }
    }

    vector<bool> neg(MAX_V,false);
    rep(i,V){
        rep(j,E){
            edge e = ed[j];
            if(p[e.from] != INF && p[e.to]> p[e.from]+e.c+P){
                p[e.to] = p[e.from]+e.c+P;
                neg[e.to] = true;
            }
            if(neg[e.from])neg[e.to];
        }
    }

    if(neg[V])cout<<-1<<endl;
    else cout<<max(-p[V],0)<<endl; return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:36: warning: ignoring return value of 'std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>; reference = std::vector<bool>::reference; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   56 |             if(neg[e.from])neg[e.to];
      |                                    ^
In file included from /usr/include/c++/14/vector:67,
                 from /usr/include/c++/14/bits/random.h:34,
                 from /usr/include/c++/14/random:48,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_bvector.h:1086:7: note: declared here
 1086 |       operator[](size_type __n)
      |       ^~~~~~~~
a.cc:61:19: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   61 |     else cout<<max(-p[V],0)<<endl; return 0;
      |                ~~~^~~~~~~~~
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:61:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   61 |     else cout<<max(-p[V],0)<<endl; return 0;
      |                ~~~^~~~~~~~~
/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:13:
/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:61:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   61 |     else cout<<max(-p[V],0)<<endl; return 0;
      |                ~~~^~~~~~~~~