Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); i++)
typedef pair<int, int> P;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const ll INF = 1e16+7;

vector<ll> to[2505];
vector<ll> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

ll V,E,p;

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

void dfs(int v) {
  if (reachableFrom1[v]) return;
  reachableFrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}

void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

bool bellman_ford(const ll &s,const ll &V,const ll &E,const vector<edge> &ed, vector<ll> &d){

    // s=スタート, Vが頂点数，Eが辺の数, ed=どのようなパスを持つか, 
    //d=答えを保持するvector．今は１つの経路が欲しいので参照して書き換えているが全ての経路について必要になった場合にはdをreturnするように改造する

    // 初期化
    for(ll i = 0; i < V; i++){
        d[i] = INF;
    }
    ll num = 0;
    d[s] = 0;
    while(true){
        if(num>V){
            return true;
        }
        //updateが更新されなくなるまでこの操作を繰り返す
        bool update = false;
        for(ll i = 0; i < E; i ++){
            edge e = ed[i];
            if(!ok[e.to])continue;
            if(!ok[e.from])continue; // 接続していないところは考えない．
            // cout << e.to << " " << e.from << endl;
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.c){
                d[e.to] = d[e.from]+e.c;
                update = true;
            }
        }
        if(!update){
            break;
        }
        num ++;
    }
    return false;
}




int main(){

     cin >> V >> E >> p;
    vector<edge> ed(E);
    rep(i,E){
        cin >> ed[i].from >> ed[i].to >> ed[i].c;
        ed[i].c = p - ed[i].c;
        to[ed[i].from].push_back(ed[i].to);
        rto[ed[i].to].push_back(ed[i].from);
    }
    vector<ll> d(V+5); // スタートの頂点番号を0ではなく１としたいので余分に作ってd[0]は使わない
    dfs(1);
    rdfs(V);
    rep(i,E) ok[i+1] = reachableFrom1[i+1]&reachableToN[i+1];
    bool loop = bellman_ford(1, V, E, ed, d);
    // rep(i,V){
    //     if(ok[i+1]){
    //         cout << i+1 << " true" << endl;
    //     }else{
    //         cout << i+1 << " false" << endl;
    //     }
    // }

    if(loop){
        cout << "-1" << endl;
    }else{
        ll ans = -d[V];
        ans = max(0, ans);
        cout << ans << endl;
    }
    

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:107:18: error: no matching function for call to 'max(int, ll&)'
  107 |         ans = max(0, ans);
      |               ~~~^~~~~~~~
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:107:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  107 |         ans = max(0, ans);
      |               ~~~^~~~~~~~
/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:107:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  107 |         ans = max(0, ans);
      |               ~~~^~~~~~~~