Language: C++

#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<iterator>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<cstdint>
#include<chrono>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

using namespace std;



signed main() {

	int N, M, P;
	cin >> N >> M >> P;
	vector<int>A(M), B(M), C(M);
	rep(i, M)cin >> A[i] >> B[i] >> C[i];

	vector<vector<int>>graph(N), graphrev(N);

	rep(i, M) {
		A[i]--;
		B[i]--;
		C[i] = -(C[i] - P);

		graph[A[i]].push_back(B[i]);
		graphrev[B[i]].push_back(A[i]);
	}

	vector<int>BF(N, intmax);
	BF[0] = 0;

	rep(i, N - 1) {
		rep(j, M) {
			BF[B[j]] = min(BF[B[j]], BF[A[j]] + C[j]);
		}
	}

	stack<int>dfs1;
	vector<int>searched1(N);
	dfs1.push(0);
	while (!dfs1.empty()) {
		int x = dfs1.top();
		dfs1.pop();
		if (searched1[x])continue;
		searched1[x] = 1;
		for (int y : graph[x]) {
			dfs1.push(y);
		}
	}
	stack<int>dfsN;
	vector<int>searchedN(N);
	dfsN.push(N-1);
	while (!dfsN.empty()) {
		int x = dfsN.top();
		dfsN.pop();
		if (searchedN[x])continue;
		searchedN[x] = 1;
		for (int y : graphrev[x]) {
			dfsN.push(y);
		}
	}


	rep(i, M) {
		if (BF[B[i]] > BF[A[i]] + C[i]) {
			if (searched1[B[i]] != 0 && searchedN[B[i]] != 0) {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	int answer = max(-BF[N - 1], 0LL);

	cout << answer << endl;




	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:105:25: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type, long long int)'
  105 |         int answer = max(-BF[N - 1], 0LL);
      |                      ~~~^~~~~~~~~~~~~~~~~
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:105:25: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  105 |         int answer = max(-BF[N - 1], 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,
                 from a.cc:12:
/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:105:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  105 |         int answer = max(-BF[N - 1], 0LL);
      |                      ~~~^~~~~~~~~~~~~~~~~