Language: C++

// //@HelloElwin-20190817
// #include <algorithm>
// #include <iostream>
// #include <cstring>
// #include <cstdio>
// #include <queue>
// using namespace std;
// int n, m, p, ghd, hd[3000];
// long long d[3000];
// bool inQ[3000];
// int cnt[3000];
// bool bk[3000];
// bool vi[3000];

// struct Edge {
// 	int u, v, w, nxt;
// }g[5005];

// void AddEdge (int a, int b, int c) {
// 	g[ghd] = (Edge){a, b, c};
// 	g[ghd].nxt = hd[a];
// 	hd[a] = ghd++;
// }

// bool Spfa () {
// 	queue<int> Q; d[1] = 0;
// 	Q.push(1); inQ[1] = true;
// 	while (!Q.empty()) {
// 		int u = Q.front();
// 		inQ[u] = false; Q.pop();
// 		for (int i = hd[u]; ~i; i = g[i].nxt) {
// 			int v = g[i].v, w = g[i].w;
// 			if (d[u] + (long long)w > d[v]) {
// 				d[v] = d[u] + (long long)w;
// 				if (inQ[v]) continue;
// 				if (++cnt[v] > n && bk[v]) return true;
// 				if (  cnt[v] > n &&!bk[v]) g[i].w = -1000000000; 
// 				inQ[v] = true;
// 				Q.push(v);

// 			}
// 		}
// 	}
// 	return 0;
// }



// int main() {
	
// 	memset(hd, -1, sizeof(hd));
// 	scanf("%d %d %d", &n, &m, &p);
// 	for (int i = 0; i <= n; i++) d[i] = -20000000000;
// 	for (int i = 0; i < m; i++) {
// 		int a, b, c;
// 		scanf("%d %d %d", &a, &b, &c);
// 		AddEdge(a, b, c - p);
// 	}

// 	bk[n] = true;
// 	GoGoGo(1);
// 	for (int i = 1; i <= n; ++i)
// 	{
// 		printf("%d ", bk[i]);
// 	}
// 	cerr<<endl;

// 	if (Spfa()) {
// 		printf("-1\n");
// 		return 0;
// 	}

// 	printf("%lld\n", max(0ll, d[n]));

// 	return 0;
// }
//@HelloElwin-20190817
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
int n, m, p, ghd, hd[3000];
long long d[3000];
bool inQ[3000];
int cnt[3000];

struct Edge {
	int u, v, w, nxt;
}g[5005];

void AddEdge (int a, int b, int c) {
	g[ghd] = (Edge){a, b, c};
	g[ghd].nxt = hd[a];
	hd[a] = ghd++;
}

bool Spfa () {
	queue<int> Q; d[1] = 0;
	Q.push(1); inQ[1] = true;
	while (!Q.empty()) {
		int u = Q.front();
		inQ[u] = false; Q.pop();
		for (int i = hd[u]; ~i; i = g[i].nxt) {
			int v = g[i].v, w = g[i].w;
			if (d[u] + w > d[v] && cnt[v] <= n) {
				d[v] = d[u] + w;
				if (inQ[v]) continue;
				++cnt[v]; 
				if (cnt[n] > n) return true;
				inQ[v] = true;
				Q.push(v);

			}
		}
	}
	return 0;
}

bool Go (int u) {
	bool flg;
	vi[u] = true;
	for (int i = hd[u]; ~i; i = g[i].nxt) {
		int v = g[i].v;
		if (!vi[u]) flg = Go(v);
		if (flg) bk[u] = true;
		if (bk[v])bk[u]= true;
	}
	return bk[u];
}

int main() {
	
	memset(hd, -1, sizeof(hd));
	scanf("%d %d %d", &n, &m, &p);
	for (int i = 0; i <= n; i++) d[i] = -2e10;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		AddEdge(a, b, c - p);
	}

	if (Spfa()) {
		printf("-1\n");
		return 0;
	}

	printf("%lld\n", max(0ll, d[n]));

	return 0;
}


Compiler output:
a.cc: In function 'bool Go(int)':
a.cc:123:9: error: 'vi' was not declared in this scope
  123 |         vi[u] = true;
      |         ^~
a.cc:127:26: error: 'bk' was not declared in this scope
  127 |                 if (flg) bk[u] = true;
      |                          ^~
a.cc:128:21: error: 'bk' was not declared in this scope
  128 |                 if (bk[v])bk[u]= true;
      |                     ^~
a.cc:130:16: error: 'bk' was not declared in this scope
  130 |         return bk[u];
      |                ^~