Language: C++

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;


template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};
int n;
vector<int> dists;
vector<int> neg;
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  for(auto &e : edges) {
    if(dist[e.src] == INF) continue;
    if(dist[e.src] + e.cost < dist[e.to]) {neg[e.to]=1;}
  }
  return dist;
}
vector<int> visited;
void dfs(int x,Edges<T> &edges){
  for(auto &e:edges){
    if(e.to==x&&!visited[e.src]){
      visited[e.src]=1;
      dfs(e.src,&edges);
    }
  }
}
main(){
    int m,p;
    cin>>n>>m>>p;
    visited.resize(n+1);
    Edges<int> es;
    rep(i,m){
      int a,b,c;
      cin>>a>>b>>c;
      c-=p;
      es.emplace_back(a,b,-c);
    }
    neg.resize(n+1);
    dists=bellman_ford(es,n+1,1);
    rep2(i,1,n){
      if(visited[i]&neg[i]){
        cout<<-1;
        return 0;
      }
    }
    cout<<max(0,-dists[n])<<endl;
}



Compiler output:
a.cc:94:22: error: 'T' was not declared in this scope
   94 | void dfs(int x,Edges<T> &edges){
      |                      ^
a.cc:94:23: error: template argument 1 is invalid
   94 | void dfs(int x,Edges<T> &edges){
      |                       ^
a.cc: In function 'void dfs(int, int&)':
a.cc:95:15: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   95 |   for(auto &e:edges){
      |               ^~~~~
      |               std::begin
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from a.cc:4:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:95:15: error: 'end' was not declared in this scope; did you mean 'std::end'?
   95 |   for(auto &e:edges){
      |               ^~~~~
      |               std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc: At global scope:
a.cc:102:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  102 | main(){
      | ^~~~