Language: C++

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

int	main()
{
	const static int64_t	inf = static_cast<int64_t>(1e+12 + 1);
	int	N, M, P;
	cin >> N >> M >> P;
	vector<int64_t>	v_score(N, -inf);
	map<int, map<int, int64_t>>	e_score;
	int	A, B, C;
	for (int i = 0; i < M; ++i) {
		cin >> A >> B >> C;
		--A; --B;
		if (!e_score.count(A))
			e_score[A] = map<int, int64_t>();	
		e_score.at(A)[B] = C - P;
	}
	v_score.at(0) = 0;
	int64_t	score;
	bool	updated;
	for (int i = 0; i < N; ++i) {
		updated = false;
		if (v_score.at(i) == -inf)
			continue;
		if (!e_score.count(i))
			continue;
		for (auto pr : e_score.at(i)) {
			B = pr.first;
			score = v_score.at(i) + pr.second;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				updated = true;
			}
		}
		if (!updated)
			break;
	}
	if (!updated) {
		cout << max(0LL, v_score.at(N - 1)) << endl;
		return 0;
	}
	vector<bool>	has_upper(N, true);
	for (int i = 0; i < N; ++i) {
		if (v_score.at(i) == -inf)
			continue;
		if (!e_score.count(i))
			continue;
		for (auto pr : e_score.at(i)) {
			B = pr.first;
			score = v_score.at(i) + pr.second;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				has_upper.at(B) = false;
			}
			if (!has_upper.at(i))
				has_upper.at(B) = false;
		}
	}
	if (has_upper.at(N - 1))
		cout << max(0LL, v_score.at(N - 1)) << endl;
	else
		cout << -1 << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:28: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   40 |                 cout << max(0LL, v_score.at(N - 1)) << 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:40:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   40 |                 cout << max(0LL, v_score.at(N - 1)) << 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:40:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   40 |                 cout << max(0LL, v_score.at(N - 1)) << endl;
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:28: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   61 |                 cout << max(0LL, v_score.at(N - 1)) << endl;
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/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:61:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   61 |                 cout << max(0LL, v_score.at(N - 1)) << 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
/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:61:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   61 |                 cout << max(0LL, v_score.at(N - 1)) << endl;
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~