Language: C++

#include <iostream>
#include <math.h>
#include <set>
#include<vector>
#include<string>
#include <algorithm>
#include<queue>
#include<map>
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define per(i,j,k) for(int i = (int)j;i >= (int)k;i --)
#define F(i,k) for(int i=(int)0;i<(int)k;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
const int maxn = 5e3 + 5;
using namespace std;
ll m,n;
ll dis[maxn];
bool inQ[maxn];
int cnt[maxn];
vector<pii> E[maxn];
int SPFA() {
	rep(i, 1, n)dis[i] = 1e18, inQ[i] = 0,cnt[i]=0;
	queue<pii> Q;
	Q.push({ 1,0 });
	dis[1] = 0;
	cnt[1]++;
	while (!Q.empty()) {
		auto now = Q.front();
		Q.pop();
		inQ[now.first] = 0;
		for (auto v : E[now.first]) {
			dis[v.first] = min(dis[v.first], dis[now.first] + v.second);
			if (!inQ[v.first]&&cnt[v.first]<=n+1)Q.push({ v.first,now.second + 1 }), inQ[v.first] = 1,cnt[v.first]++;
		}
	}
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int p;
	cin >> n >> m >> p;

	rep(i, 1, m) {
		int x, y, z;
		cin >> x >> y >> z;
		E[x].push_back({y,  p - z });
	}
	SPFA();
	if (cnt[n] >= n + 1)cout << -1<<endl;
	 else cout << max(0,-dis[n]) << endl;
		cin >> m;
}

/*
2 2 10
1 2 100
2 2 100
*/

Compiler output:
a.cc: In function 'int SPFA()':
a.cc:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
   37 | }
      | ^
a.cc: In function 'int main()':
a.cc:50:26: error: no matching function for call to 'max(int, ll)'
   50 |          else cout << max(0,-dis[n]) << endl;
      |                       ~~~^~~~~~~~~~~
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:50:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   50 |          else cout << max(0,-dis[n]) << 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,
                 from a.cc:6:
/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:50:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   50 |          else cout << max(0,-dis[n]) << endl;
      |                       ~~~^~~~~~~~~~~