Language: C++

#include <bits/stdc++.h>

struct Edge {
	int to;
	int64_t dist{1};

	// int64_t cost;
	// int from;
	// int rev_i;
};
using EdgeVec = std::vector<Edge>;
using EdgeLists = std::vector<EdgeVec>;

template <typename Metric = int64_t>
class BellmanFord {
private:
	const EdgeLists& edges_;
	const int source_;
	std::vector<Metric> distance_;
public:
	const Metric inf, negative_inf;

	BellmanFord(const EdgeLists& edges, const int source)
		: edges_(edges), source_(source), distance_(edges.size(), std::numeric_limits<Metric>::max()),
		inf(std::numeric_limits<Metric>::max()), negative_inf(std::numeric_limits<Metric>::min())
	{
		distance_[source] = 0;
		for (int loop{}; loop < (int)edges_.size(); loop++)
			for (int now{}; now < (int)edges_.size(); now++)
				if (distance_[now] != inf)
					for (const Edge& next: edges_[now])
						distance_[next.to] = std::min(distance_[next.to], distance_[now] + next.dist);
		
		std::vector<bool> isInCycle(edges_.size());
		std::queue<int> updatedQueue;
		for (int from{}; from < (int)edges_.size(); from++)
			if (distance_[from] != inf)
				for (const Edge& next: edges_[from])
					if (!isInCycle[next.to] && distance_[from] + next.dist < distance_[next.to])
					{
						isInCycle[next.to] = true;
						updatedQueue.push(next.to);
					}
		while (!updatedQueue.empty())
		{
			int now{updatedQueue.front()};
			updatedQueue.pop();
			distance_[now] = negative_inf;
			for (const Edge& next: edges_[now])
				if (!isInCycle[next.to])
				{
					isInCycle[next.to] = true;
					updatedQueue.push(next.to);
				}
		}
	}

	// get distance_
	Metric operator[](const int index) const
	{
		return distance_[index];
	}

	decltype(distance_.begin()) begin() { return distance_.begin(); }
	decltype(distance_.end()) end() { return distance_.end(); }

	bool negativeCycleExists() const
	{
		for (const Metric& dist: distance_)
			if (dist == negative_inf)
				return true;
		return false;
	}
};

int main()
{
	int N, M, P;
	scanf("%d%d%d", &N, &M, &P);
	EdgeLists edges(N);
	for (int i{}; i < M; i++)
	{
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		A--; B--;
		edges[A].push_back({B, P - C});
	}
	BellmanFord<> bellmanFord(edges, 0);
	if (bellmanFord[N - 1] == bellmanFord.negative_inf)
		puts("-1");
	else
		printf("%lld\n", std::max(-bellmanFord[N - 1], 0ll));
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:92:42: error: no matching function for call to 'max(long int, long long int)'
   92 |                 printf("%lld\n", std::max(-bellmanFord[N - 1], 0ll));
      |                                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
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:92:42: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   92 |                 printf("%lld\n", std::max(-bellmanFord[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:
/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:92:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   92 |                 printf("%lld\n", std::max(-bellmanFord[N - 1], 0ll));
      |                                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~