Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

//136 E
ll d[2500];

int main(void) {
	ll n, m, p;
	cin >> n >> m >> p;
	vector<vector<pair<ll,ll>>> graph = vector<vector<pair<ll,ll>>>(n, vector<pair<ll,ll>>());
	rep(i, 0, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		graph[a - 1].push_back(make_pair(b - 1, c-p));
	}

	//ここからnまでいける
	vector<ll> reachable_from = vector<ll>(n,0);
	//1からここまでいける
	vector<ll> reachable_to = vector<ll>(n, 0);
	queue<ll> q = queue<ll>();
	q.push(n-1);
	while (q.size() > 0) {
		ll v = q.front();
		q.pop();
		if (reachable_from[v])continue;	
		reachable_from[v] = 1;
		rep(i, 0, n) {
			rep(j, 0, graph[i].size()) {
				ll from = i;
				ll to = graph[i][j].first;
				if (v == to) {
					q.push(from);
				}
			}
		}
	}

	q.push(0);
	while (q.size() > 0) {
		ll v = q.front();
		q.pop();
		if (reachable_to[v])continue;
		reachable_to[v] = 1;
		rep(i, 0, n) {
			rep(j, 0, graph[i].size()) {
				ll from = i;
				ll to = graph[i][j].first;
				if (v == from) {
					q.push(to);
				}
			}
		}
	}

	vector<vector<pair<ll,ll>>> newGraph = vector<vector<pair<ll,ll>>>(n,vector<pair<ll,ll>());
	rep(i, 0, n) {
		rep(j, 0, graph[i].size()) {
			ll from = i;
			ll to = graph[i][j].first;
			if (reachable_to[from] && reachable_from[to]) {
				newGraph[from].push_back(graph[i][j]);
			}
		}
	}



	const ll INF = 1e12;
	rep(i, 0, 2500)d[i] = -INF;
	d[0] = 0;
	ll loopCount = 0;
	bool isInf = false;
	while (true) {
		loopCount++;
		bool update = false;
		bool vnUpdate = false;
		rep(i, 0, n) {
			for(const auto& pr : newGraph[i]) {
				ll from = i;
				ll to = pr.first;
				ll cost = pr.second;
				if (d[from] != -INF && d[to] < d[from] + cost) {
					d[to] = d[from] + cost;
					update = true;
				}
			}
		}
		if (!update) break;
		else if (loopCount >= 2*n) {
			isInf = true;
			break;
		}
	}
	if (isInf) cout << -1 << endl;
	else if (d[n - 1] < 0) cout << 0 << endl;
	else cout << d[n - 1] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:108:97: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
  108 |         vector<vector<pair<ll,ll>>> newGraph = vector<vector<pair<ll,ll>>>(n,vector<pair<ll,ll>());
      |                                                                                                 ^
a.cc:108:97: note:   expected a type, got 'std::pair<long long int, long long int>()'
a.cc:108:97: error: template argument 2 is invalid