Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct edge {int from;int to;ll cost;};

typedef pair<ll, ll> P;

vector<edge> es;
vector<edge> new_es;

ll dist[2505];
ll inf=pow(1,50);

std::vector<int> g[2505];
std::vector<int> rev_g[2505];

int ok1[2505];
int ok2[2505];

ll n,m,p;

bool ok(int v) {
  return ok1[v]&&ok2[v];
}

void bfs1(int v) {
  ok1[v]=1;
  for(int i=0;i<g[v].size();i++){
    int u = g[v][i];
    if(ok1[u])continue;
    bfs1(u);
  }
}

void bfs2(int v) {
  ok2[v]=1;
  for(int i=0;i<rev_g[v].size();i++){
    int u = rev_g[v][i];
    if(ok2[u])continue;
    bfs2(u);
  }
}

void prepare() {
  for(int i=0;i<2505;i++)dist[2505]=inf;

  cin>>n>>m>>p;
  for(int i=0;i<m;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    a--,b--;
    es.push_back({a,b,-(c-p)});
    g[a].push_back(b);
    rev_g[b].push_back(a);
  }
}

void solve(){
  dist[0]=0;
  int cnt=0;
  while(1){
    cnt++;
    bool update = 0;
    for(int i=0;i<new_es.size();i++){
      edge e = new_es[i];
      if(dist[e.to]>dist[e.from]+e.cost){
        dist[e.to]=dist[e.from]+e.cost;
        if(e.to==e.from){
          cout<<-1<<endl;
          exit(0);
        }
        update=1;
      }
    }
    if(!update)break;
    if(cnt>3*n){
      cout<<-1<<endl;
      exit(0);
    }
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  prepare();
  bfs1(0);
  bfs2(n-1);
  for(auto e : es) {
    if(ok(e.from)&&ok(e.to))
      new_es.push_back(e);
  }
  solve();

  cout<<max(dist[n-1]*-1, 0)<<endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:99:12: error: no matching function for call to 'max(ll, int)'
   99 |   cout<<max(dist[n-1]*-1, 0)<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~
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:99:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   99 |   cout<<max(dist[n-1]*-1, 0)<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~
/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:99:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   99 |   cout<<max(dist[n-1]*-1, 0)<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~