Language: C++

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


class edge {
public:
    edge(int to, long long cost);
    int get_to() const;
    long long get_cost() const;
private:
    int to;
    long long cost;
};

edge::edge(int to, long long cost) : to(to), cost(cost) {}

int edge::get_to() const { return to; }

long long edge::get_cost() const { return cost; }


class bellman_ford {
private:
    //unordered_mapを使って隣接グラフを構築
    //first:接続元、second:辺のコストと接続先
    std::unordered_map<int, std::vector<edge>> adj_list;
    int node_num;
    int start_point;
    std::vector<int> pred;//経路（遷移元）を保持
    std::vector<long long> costs;//距離を保持
    bool is_negative_graph;//グラフ内に負のサイクルをもつか否か
    std::vector<bool> is_negative_pass;//経路上に負のサイクルを持つか否か

public:
    bellman_ford(const int node_num, const std::unordered_map<int, std::vector<edge>>& adj_list);
    void calc_min_cost(int start);
    long long get_cost(int end) const;
    bool get_is_negative_graph() const;
    std::vector<int> get_min_path(int end) const;
};

bellman_ford::bellman_ford(const int node_num,
    const std::unordered_map<int, std::vector<edge>>& adj_list) :
    adj_list(adj_list),
    start_point(0),
    node_num(node_num),
    pred(node_num + 1, INT_MAX),
    costs(node_num + 1, LLONG_MAX),
    is_negative_graph(false),
    is_negative_pass(node_num + 1, false)
{}

void bellman_ford::calc_min_cost(int start) {
    this->start_point = start;
    this->pred = std::vector<int>(node_num + 1, INT_MAX);
    this->costs = std::vector<long long>(node_num + 1, LLONG_MAX);
    this->is_negative_pass = std::vector<bool>(node_num + 1, false);

    pred[start] = -1;
    costs[start] = 0;
    for (int i = 0; i < 2 * node_num; i++) {
        for (auto &node : adj_list) {
            if (costs[node.first] == LLONG_MAX) continue;
            for (auto &adj : adj_list[node.first]) {
                int adj_node = adj.get_to();
                long long adj_cost = adj.get_cost() + costs[node.first];
                if (adj_cost < costs[adj_node]) {//計算された隣接頂点のコストが現在のコストより小さいなら
                    costs[adj_node] = adj_cost;//隣接頂点のコストを更新
                    pred[adj_node] = node.first;//隣接頂点の遷移元を更新
                    if (i >= node_num - 1) {
                        //頂点数回以上繰り返しても、
                        //まだ更新が発生するなら、その頂点への経路には負のサイクルあり
                        is_negative_pass[adj_node] = true;
                        is_negative_graph = true;
                    }
                }
                if (is_negative_pass[node.first] == true) {//負のサイクル情報伝搬
                                                           //経路に負のサイクルを含む頂点に連結されているなら、
                                                           //その頂点への経路も負のサイクルを含む
                    is_negative_pass[adj_node] = true;
                }
            }
        }
    }
}

bool bellman_ford::get_is_negative_graph() const {
    return is_negative_graph;
}

long long bellman_ford::get_cost(int end) const {
    if (is_negative_pass[end] == false)
        return costs[end];
    else
        return LLONG_MIN;
}

std::vector<int> bellman_ford::get_min_path(int end) const {
    int node = end;
    std::vector<int> vec;
    vec.push_back(node);
    //終点から始点までの経路をたどる
    while (1) {
        //負のサイクルを含む頂点or
        //始点から辿れない頂点or
        //始点であれば終了
        if (is_negative_pass[node] == true ||
            pred[node] >= INT_MAX || pred[node] == -1) break;
        node = pred[node];
        vec.push_back(node);
    }
    std::reverse(vec.begin(), vec.end());
    return vec;
}

int main() {
    int N, M, P;
    cin >> N >> M >> P;
    unordered_map<int, std::vector<edge>> graph;
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        edge e(b, ll(- (c - P)));
        if(c)
        graph[a].push_back(e);
    }
    bellman_ford bf(N, graph);
    bf.calc_min_cost(1);
    if (bf.get_cost(N) == LLONG_MIN) {
        cout << -1 << endl;
    }
    else {
        
        cout << max(0LL, -bf.get_cost(N)) << endl;
    }
    return 0;
}

Compiler output:
a.cc: In constructor 'bellman_ford::bellman_ford(int, const std::unordered_map<int, std::vector<edge> >&)':
a.cc:90:24: error: 'INT_MAX' was not declared in this scope
   90 |     pred(node_num + 1, INT_MAX),
      |                        ^~~~~~~
a.cc:29:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   28 | #include <functional>
  +++ |+#include <climits>
   29 | using namespace std;
a.cc:91:25: error: 'LLONG_MAX' was not declared in this scope
   91 |     costs(node_num + 1, LLONG_MAX),
      |                         ^~~~~~~~~
a.cc:91:25: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In member function 'void bellman_ford::calc_min_cost(int)':
a.cc:98:49: error: 'INT_MAX' was not declared in this scope
   98 |     this->pred = std::vector<int>(node_num + 1, INT_MAX);
      |                                                 ^~~~~~~
a.cc:98:49: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:99:56: error: 'LLONG_MAX' was not declared in this scope
   99 |     this->costs = std::vector<long long>(node_num + 1, LLONG_MAX);
      |                                                        ^~~~~~~~~
a.cc:99:56: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In member function 'long long int bellman_ford::get_cost(int) const':
a.cc:138:16: error: 'LLONG_MIN' was not declared in this scope
  138 |         return LLONG_MIN;
      |                ^~~~~~~~~
a.cc:138:16: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In member function 'std::vector<int> bellman_ford::get_min_path(int) const':
a.cc:151:27: error: 'INT_MAX' was not declared in this scope
  151 |             pred[node] >= INT_MAX || pred[node] == -1) break;
      |                           ^~~~~~~
a.cc:151:27: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In function 'int main()':
a.cc:172:27: error: 'LLONG_MIN' was not declared in this scope
  172 |     if (bf.get_cost(N) == LLONG_MIN) {
      |                           ^~~~~~~~~
a.cc:172:27: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'