Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;

// 頂点fromから頂点toへのコストcostの辺
struct bf_edge {
    int from;
    int to;
    int cost;
};

class Bellman_Ford{
public:
    vector<bf_edge> es; // 辺
    vector<int> d; // d[i]...頂点sから頂点iまでの最短距離
    int V, E; // Vは頂点数、Eは辺数

    Bellman_Ford(int v, int e) {
        V = v;
        E = e;
        d = vector<int>(v);
    }

    void add(int from, int to, int cost) {
        bf_edge ed = {from, to, cost};
        es.push_back(ed);
    }

    // s番目の頂点から各頂点INFへの最短距離を求める
    // trueなら負の閉路が存在する
    bool shortest_path(int s) {
        for(int i = 0; i < V; i++) {
            d[i] = INF;
        }
        d[s] = 0;
        for (int i = 0; i < 3*V; i++) {
            for(int j = 0; j < E; j++) {
                bf_edge e = es[j];
                if(d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;

                    // 3n回目にも更新があるなら負の閉路が存在する
                    if(i == V - 1)return true;
                }
            }
        }
        return false;
    }
};

void dfs(int pos, vvi &v, vi &ok) {
    ok[pos]=1;
    for(auto i: v[pos]){
        if(!ok[i])dfs(i,v,ok);
    }
}

int main() {

    int n,m,k;
    cin>>n>>m>>k;
    vi a(m),b(m),c(m);
    vvi v(n),rv(n);
    vi ok(n,0),ok2(n,0);
    rep(i,m){
        int A,B,C;
        cin>>A>>B>>C;
        A--;B--;
        C-=k;
        C=-C;
        a[i]=A;
        b[i]=B;
        c[i]=C;
        v[A].pb(B);
        rv[B].pb(A);
    }
    dfs(0,v,ok);
    dfs(n-1,rv,ok2);
    vvi edge;
    rep(i,m){
        if(ok[a[i]]&&ok[b[i]]&&ok2[a[i]]&&ok2[b[i]]){
            vi v;
            v.pb(a[i]);
            v.pb(b[i]);
            v.pb(c[i]);
            edge.pb(v);
        }
    }
    Bellman_Ford bf(n,edge.size());
    rep(i,edge.size()){
        bf.add(edge[i][0],edge[i][1],edge[i][2]);
    }
    if(bf.shortest_path(0)){
        fin(-1);
    } else {
        int ans=bf.d[n-1]*(-1);
        fin(max(ans,0LL));
    }

}



Compiler output:
a.cc: In function 'int main()':
a.cc:165:16: error: no matching function for call to 'max(int&, long long int)'
  165 |         fin(max(ans,0LL));
      |             ~~~^~~~~~~~~
a.cc:44:27: note: in definition of macro 'fin'
   44 | #define fin(ans) cout << (ans) << '\n'
      |                           ^~~
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:165:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  165 |         fin(max(ans,0LL));
      |             ~~~^~~~~~~~~
a.cc:44:27: note: in definition of macro 'fin'
   44 | #define fin(ans) cout << (ans) << '\n'
      |                           ^~~
/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:3:
/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:165:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  165 |         fin(max(ans,0LL));
      |             ~~~^~~~~~~~~
a.cc:44:27: note: in definition of macro 'fin'
   44 | #define fin(ans) cout << (ans) << '\n'
      |                           ^~~