Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
#define int long long

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

int P;
template <typename T>
pair<vector<T>, vector<int>> bellman_ford(Edges<T> &edges, int V, int s, int MA) {
    const T INF = numeric_limits<T>::max();
    vector<T> dist(V, INF); dist[s] = 0;
    vector<int> cnt(V, 0); cnt[s] = 0;
    vector<T> memo(V);
    vector<int> memo_c(V);
    vector<int> prev(V, -1);
    for (int i = 0; i < MA; i++) {
        for (auto &e: edges) if (dist[e.src] != INF) {
            if (dist[e.dst] > dist[e.src] + e.cost) {
                dist[e.dst] = dist[e.src] + e.cost;
                cnt[e.dst] = cnt[e.src] + 1;
                prev[e.dst] = e.src;
            }
        }
        memo[i] = dist[V - 1];
        memo_c[i] = cnt[V - 1];
    }
    return {memo, prev};
}

signed main() {
    int N, M; cin >> N >> M >> P;
    Edges<long long> es;
    while (M--) {
        int s, t, d; cin >> s >> t >> d; s--, t--;
        es.emplace_back(s, t, -d + P);
    }
    auto res1 = bellman_ford(es, N, 0, 2 * N);
    long long ans1 = -res1.first[N - 2];
    long long ans2 = -res2.first[2 * N - 1];
    if (ans1 < ans2) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, ans1) << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'std::pair<std::vector<_Tp>, std::vector<long long int> > bellman_ford(Edges<T>&, long long int, long long int, long long int)':
a.cc:21:19: error: 'numeric_limits' was not declared in this scope
   21 |     const T INF = numeric_limits<T>::max();
      |                   ^~~~~~~~~~~~~~
a.cc:21:35: error: expected primary-expression before '>' token
   21 |     const T INF = numeric_limits<T>::max();
      |                                   ^
a.cc:21:41: error: no matching function for call to 'max()'
   21 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
In file included from /usr/include/c++/14/algorithm:60,
                 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:   candidate expects 2 arguments, 0 provided
/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, 0 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, 0 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:   candidate expects 2 arguments, 0 provided
a.cc: In function 'int main()':
a.cc:50:23: error: 'res2' was not declared in this scope; did you mean 'res1'?
   50 |     long long ans2 = -res2.first[2 * N - 1];
      |                       ^~~~
      |                       res1