Language: C++

#include <bits/stdc++.h>

template<typename T>
class fixed_point : T {#include <bits/stdc++.h>

template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (T&& t) noexcept
      : T(std::forward<T>(t)) {}
    template<typename... Args>
    constexpr decltype(auto) operator()(Args&&... args) const
      {return T::operator()(*this, std::forward<Args>(args)...);}
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{std::forward<T>(t)};
}

template <typename Label>
struct edge
{
  using index_type = int;
  using label_type = Label;

  index_type from;
  index_type to;
  label_type label;
};

template <typename Label>
class graph_base
{
public:
  using size_type           = int;
  using index_type          = int;
  using label_type          = Label;
  using edge_type           = edge<label_type>;
  using adjacency_list_type = std::vector<std::vector<edge_type>>;
  using edge_list_type      = std::vector<edge_type>;

private:
  adjacency_list_type         adjacency_list;
  edge_list_type              edge_list;

public:
  graph_base()=default;
  graph_base(const graph_base&)=default;
  graph_base(graph_base&&)=default;
  graph_base& operator=(const graph_base&)=default;
  graph_base& operator=(graph_base&&)=default;

  graph_base(size_type n) :
    adjacency_list(n),
    edge_list()
    {}

  // Element access
  const auto& at       (index_type i) const {return adjacency_list.at(i);}

  // Iterators
  auto begin           ()             const {return edge_list.begin();}

  auto end             ()             const {return edge_list.end();}

  // Capacity
  auto size            ()             const {return adjacency_list.size();}

  void insert_edge
  (
    index_type from,
    index_type to,
    label_type label
  )
  {
    adjacency_list.at(from).push_back({from, to, label});
    edge_list.push_back({from, to, label});
  }
};

template <typename Graph>
auto bellman_ford
(
  const Graph&                     graph,
  const typename Graph::index_type start
)
-> std::pair<
  std::vector<typename Graph::label_type>, // shortest path length
  std::vector<bool>                        //  `true` if infinitely near
>
{
  using label_type         = typename Graph::label_type;
  using label_vector_type  = std::vector<typename Graph::label_type>;

  constexpr label_type inf = std::numeric_limits<label_type>::max();

  int n = graph.size();
  auto distance        = label_vector_type(n, inf);
  auto infinitely_near = std::vector<bool>(n, false);
  distance.at(start) = 0;

  auto relax = [&](bool check_renew = false)
  {
    for (auto e : graph)
    {
      if (distance.at(e.from) == inf) continue;
      if (distance.at(e.to) > distance.at(e.from) + e.label)
      {
        if (check_renew) {
          distance.at(e.to) = -inf;
          infinitely_near.at(e.to) = true;
        } else {
          distance.at(e.to) = distance.at(e.from) + e.label;
        }
      }
    }
  };

  for (int i = 0; i < n; i++) relax();
  for (int i = 0; i < n; i++) relax(true);
  return {distance, infinitely_near};
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, m, p;
  std::cin >> n >> m >> p;
  auto start = 0, goal = n - 1;
  auto graph = graph_base<int>(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    graph.insert_edge(a, b, p - c);
  }
  std::vector<int> ckd(n, false), dead(n, true);
  dead.at(goal) = false;
  fix ([&](auto dfs, int crr) -> void {
    ckd.at(crr) = true;
    for (auto const& e : graph.at(crr)) {
      auto nxt = e.to;
      if (ckd.at(nxt)) continue;
      dfs(nxt);
      dead.at(crr) &= dead.at(nxt);
    }
  })(start);
  auto pair            = bellman_ford(graph, start);
  auto distance        = pair.first;
  auto infinitely_near = pair.second;
  if (infinitely_near.at(goal))
  {
    std::cout << -1 << std::endl;
    return 0;
  }
  auto dst  = pair.first;
  std::cout << std::max(0, -distance.at(goal)) << std::endl;
  return 0;
}
  public:
    explicit constexpr fixed_point (T&& t) noexcept
      : T(std::forward<T>(t)) {}
    template<typename... Args>
    constexpr decltype(auto) operator()(Args&&... args) const
      {return T::operator()(*this, std::forward<Args>(args)...);}
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{std::forward<T>(t)};
}

template <typename Label>
struct edge
{
  using index_type = int;
  using label_type = Label;

  index_type from;
  index_type to;
  label_type label;
};

template <typename Label>
class graph_base
{
public:
  using size_type           = int;
  using index_type          = int;
  using label_type          = Label;
  using edge_type           = edge<label_type>;
  using adjacency_list_type = std::vector<std::vector<edge_type>>;
  using edge_list_type      = std::vector<edge_type>;

private:
  adjacency_list_type         adjacency_list;
  edge_list_type              edge_list;

public:
  graph_base()=default;
  graph_base(const graph_base&)=default;
  graph_base(graph_base&&)=default;
  graph_base& operator=(const graph_base&)=default;
  graph_base& operator=(graph_base&&)=default;

  graph_base(size_type n) :
    adjacency_list(n),
    edge_list()
    {}

  // Element access
  const auto& at       (index_type i) const {return adjacency_list.at(i);}

  // Iterators
  auto begin           ()             const {return edge_list.begin();}

  auto end             ()             const {return edge_list.end();}

  // Capacity
  auto size            ()             const {return adjacency_list.size();}

  void insert_edge
  (
    index_type from,
    index_type to,
    label_type label
  )
  {
    adjacency_list.at(from).push_back({from, to, label});
    edge_list.push_back({from, to, label});
  }
};

template <typename Graph>
auto bellman_ford
(
  const Graph&                     graph,
  const typename Graph::index_type start
)
-> std::pair<
  std::vector<typename Graph::label_type>, // shortest path length
  std::vector<bool>                        //  `true` if infinitely near
>
{
  using label_type         = typename Graph::label_type;
  using label_vector_type  = std::vector<typename Graph::label_type>;

  constexpr label_type inf = std::numeric_limits<label_type>::max();

  int n = graph.size();
  auto distance        = label_vector_type(n, inf);
  auto infinitely_near = std::vector<bool>(n, false);
  distance.at(start) = 0;

  auto relax = [&](bool check_renew = false)
  {
    for (auto e : graph)
    {
      if (distance.at(e.from) == inf) continue;
      if (distance.at(e.to) > distance.at(e.from) + e.label)
      {
        distance.at(e.to) = distance.at(e.from) + e.label;
        if (check_renew) {
          infinitely_near.at(e.to) = true;
        }
      }
    }
  };

  for (int i = 0; i < n; i++) relax();
  for (int i = 0; i < n; i++) relax(true);
  return {distance, infinitely_near};
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, m, p;
  std::cin >> n >> m >> p;
  auto start = 0, goal = n - 1;
  auto graph = graph_base<int>(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    graph.insert_edge(a, b, p - c);
  }
  std::vector<int> ckd(n, false), dead(n, true);
  dead.at(goal) = false;
  fix ([&](auto dfs, int crr) -> void {
    ckd.at(crr) = true;
    for (auto const& e : graph.at(crr)) {
      auto nxt = e.to;
      if (ckd.at(nxt)) continue;
      dfs(nxt);
      dead.at(crr) &= dead.at(nxt);
    }
  })(start);
  auto pair            = bellman_ford(graph, start);
  auto distance        = pair.first;
  auto infinitely_near = pair.second;
  if (infinitely_near.at(goal))
  {
    std::cout << -1 << std::endl;
    return 0;
  }
  auto dst  = pair.first;
  std::cout << std::max(0, -distance.at(goal)) << std::endl;
  return 0;
}

Compiler output:
a.cc:4:24: error: stray '#' in program
    4 | class fixed_point : T {#include <bits/stdc++.h>
      |                        ^
a.cc:4:25: error: 'include' does not name a type
    4 | class fixed_point : T {#include <bits/stdc++.h>
      |                         ^~~~~~~
a.cc:15:10: error: declaration of template parameter 'T' shadows template parameter
   15 | template<typename T>
      |          ^~~~~~~~
a.cc:3:10: note: template parameter 'T' declared here
    3 | template<typename T>
      |          ^~~~~~~~