Language: C++

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <cmath>

#define int ll

#define for0(i, n)    for (int i = 0  ; i <  (n); ++i)
#define for1n(i, n)   for (int i = 1  ; i <= (n); ++i)
#define for1(i, n)    for (int i = 1  ; i <  (n); ++i)
#define forn(i, n)    for (int i = 0  ; i <= (n); ++i)
#define forx(i, n, x) for (int i = (x); i <  (n); ++i)

using namespace std;

typedef long long ll;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll> ,greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;


struct edge{
    int to, cost;
};

struct node{
    int value;
    vector<edge> edges;
    node(int v) : value(v){}
};

class graph{
public:
    vector<node> nodes;
    graph(int N, int value) : nodes(N, value){};

    void addNode(int index, int value){
        nodes[index].value=value;
    }
    void addEdge(int from, int to, int cost){
        nodes[from].edges.push_back({to,cost});
    }
};

class bellmanford : public graph{
    int N;
    int P;
public:
    bool changed;
    bellmanford(int n, int p):
        graph::graph(n, std::numeric_limits<int>::min()),
        N(n),
        P(p),
        changed(false){}

    void run(int start, int end){
        nodes[start].value = 0;
        changed = r({start}, N-1, end);
    }

    bool r(vector<int> froms, int termination, int end){
        vector<int> f;
        auto old = nodes[end].value;

        for (auto& from : froms){
            for (auto& i : nodes[from].edges) {
                nodes[i.to].value = max(max(0, i.cost + nodes[from].value - P),
                                        nodes[i.to].value);
                f.push_back(i.to);
            }
        }

        if (!termination) return old != nodes[end].value;

        return r(f, termination-1, end);
    }
};


int main(void){
    int N,M,P;

    cin >> N >> M >> P;

    bellmanford bf(N, P);

    for0(i, N){
        int a,b,c;
        cin >> a >> b >> c;
        bf.addEdge(a-1, b-1, c);
    }

    bf.run(0,N-1);

    cout << (bf.changed ? -1 : bf.nodes[N-1].value);

    return 0;
}


Compiler output:
a.cc: In member function 'bool bellmanford::r(std::vector<long long int, std::allocator<long long int> >, ll, ll)':
a.cc:79:44: error: no matching function for call to 'max(int, ll)'
   79 |                 nodes[i.to].value = max(max(0, i.cost + nodes[from].value - P),
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:2:
/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:79:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   79 |                 nodes[i.to].value = max(max(0, i.cost + nodes[from].value - P),
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:6:
/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:79:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   79 |                 nodes[i.to].value = max(max(0, i.cost + nodes[from].value - P),
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:17:13: error: '::main' must return 'int'
   17 | #define int ll
      |             ^~
a.cc:92:1: note: in expansion of macro 'int'
   92 | int main(void){
      | ^~~