Language: C++

#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

const int N = 2505;
const int oo = (ll)1e15;
typedef tuple<int, int, int> TEdge;

int n, m, p, u, v, c;
vector<int> d[2];
TEdge e[N * 2];

void BellmanFord(int s, vector<int>& d, bool rev) {
    d.resize(n + 1); fill(d.begin(), d.end(), oo); d[s] = 0;
    for(int i = 1; i < n; ++i) {
        for(int j = 1; j <= m; ++j) {
            tie(u, v, c) = e[j];
            if(rev && d[v] < oo) d[u] = min(d[u], d[v] + c);
            else if(!rev && d[u] < oo) d[v] = min(d[v], d[u] + c);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m >> p;
    for(int i = 1; i <= m; ++i) {
        cin >> u >> v >> c;
        e[i] = make_tuple(u, v, p - c);
    }
    BellmanFord(1, d[0], 0);
    BellmanFord(n, d[1], 1);
    for(int i = 1; i <= m; ++i) {
        tie(u, v, c) = e[i];
        if(d[0][v] > d[0][u] + c && d[1][v] < oo && d[0][u] < oo) return cout << -1, 0;
    }
    cout << max(-d[0][n], 0ll);
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:49:16: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type, long long int)'
   49 |     cout << max(-d[0][n], 0ll);
      |             ~~~^~~~~~~~~~~~~~~
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:49:16: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   49 |     cout << max(-d[0][n], 0ll);
      |             ~~~^~~~~~~~~~~~~~~
/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:49:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   49 |     cout << max(-d[0][n], 0ll);
      |             ~~~^~~~~~~~~~~~~~~