Language: C++

#include <bits/stdc++.h>
#define M 1000000007
#define U 998244353
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define N 2505
#define U 998244353
#define bs binary_search
#define endl '\n'
#define FILEIO     freopen("input.txt","r",stdin); freopen("output.txt","w", stdout);
#define PI 3.1415926535
#define INF (int)1e15
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int po(int n, int exp){
    int prod=1;
    rep(i,0,exp)
        prod*=n;
    return prod;
}
int n,m,p;
vector<int> g[N];
vector<pair<pair<int,int>,int>> edge;
vector<int> vis(N,0);
int dfs(int i, int d)
{
    if(i==d) return 1;
    if(vis[i]) return 0;
    // if(d==n) cout<<i<<" ";
    vis[i] = 1;
    int ans = 0;
    rep(j,0,sz(g[i]))
        ans = ans|dfs(g[i][j], d);
    return ans;
}
map<pair<int,int>,int> mp;
signed main()
{
    ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        cin>>n>>m>>p;
        int tm = m;
        while(tm--){
            int a,b,w;
            cin>>a>>b>>w;
            edge.pb({{a,b},-max(0LL,w-p)});
            g[a].pb(b);
        }
        vector<int> d(N,INF);
        d[1] = 0;
        rep(i,0,n-1){
            rep(j,0,m){
                if(d[edge[j].fr.fr]<INF)
                    d[edge[j].fr.sc] = min(d[edge[j].fr.sc], d[edge[j].fr.fr]+edge[j].sc);
            }
        }
        vector<int> change;
        rep(j,0,m){
            if(d[edge[j].fr.fr]<INF){
                // trace(edge[j].fr.fr, edge[j].fr.sc, d[edge[j].fr.fr], d[edge[j].fr.sc]);
                if(d[edge[j].fr.sc]>d[edge[j].fr.fr]+edge[j].sc) change.pb(edge[j].fr.sc);
            }
        }
        for(auto j:change){
            // cout<<j;
            vis.assign(N,0);
            if(dfs(1,j)){
                vis.assign(N,0);
                if(dfs(j,n)){
                    cout<<-1;
                    r0;
                }
            }
        }
        cout<<-d[n];
    }   
} 
#include <bits/stdc++.h>
#define M 1000000007
#define U 998244353
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define N 2505
#define U 998244353
#define bs binary_search
#define endl '\n'
#define FILEIO     freopen("input.txt","r",stdin); freopen("output.txt","w", stdout);
#define PI 3.1415926535
#define INF (int)1e15
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int po(int n, int exp){
    int prod=1;
    rep(i,0,exp)
        prod*=n;
    return prod;
}
int n,m,p;
vector<int> g[N];
vector<pair<pair<int,int>,int>> edge;
vector<int> vis(N,0);
int dfs(int i, int d)
{
    if(i==d) return 1;
    if(vis[i]) return 0;
    // if(d==n) cout<<i<<" ";
    vis[i] = 1;
    int ans = 0;
    rep(j,0,sz(g[i]))
        ans = ans|dfs(g[i][j], d);
    return ans;
}
map<pair<int,int>,int> mp;
signed main()
{
    ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        cin>>n>>m>>p;
        int tm = m;
        while(tm--){
            int a,b,w;
            cin>>a>>b>>w;
            edge.pb({{a,b},p-w});
            g[a].pb(b);
        }
        vector<int> d(N,INF);
        d[1] = 0;
        rep(i,0,n-1){
            rep(j,0,m){
                if(d[edge[j].fr.fr]<INF)
                    d[edge[j].fr.sc] = min(d[edge[j].fr.sc], d[edge[j].fr.fr]+edge[j].sc);
            }
        }
        vector<int> change;
        rep(j,0,m){
            if(d[edge[j].fr.fr]<INF){
                // trace(edge[j].fr.fr, edge[j].fr.sc, d[edge[j].fr.fr], d[edge[j].fr.sc]);
                if(d[edge[j].fr.sc]>d[edge[j].fr.fr]+edge[j].sc) change.pb(edge[j].fr.sc);
            }
        }
        for(auto j:change){
            // cout<<j;
            vis.assign(N,0);
            if(dfs(1,j)){
                vis.assign(N,0);
                if(dfs(j,n)){
                    cout<<-1;
                    r0;
                }
            }
        }
      	if(d[n]>0){
          cout<<0;
          r0;
        }
        cout<<-d[n];
    }   
} 


Compiler output:
a.cc:124:6: error: redefinition of 'template<class Arg1> void __f(const char*, Arg1&&)'
  124 | void __f(const char* name, Arg1&& arg1){
      |      ^~~
a.cc:25:6: note: 'template<class Arg1> void __f(const char*, Arg1&&)' previously declared here
   25 | void __f(const char* name, Arg1&& arg1){
      |      ^~~
a.cc:128:6: error: redefinition of 'template<class Arg1, class ... Args> void __f(const char*, Arg1&&, Args&& ...)'
  128 | void __f(const char* names, Arg1&& arg1, Args&&... args){
      |      ^~~
a.cc:29:6: note: 'template<class Arg1, class ... Args> void __f(const char*, Arg1&&, Args&& ...)' previously declared here
   29 | void __f(const char* names, Arg1&& arg1, Args&&... args){
      |      ^~~
a.cc:131:5: error: redefinition of 'long long int po(long long int, long long int)'
  131 | int po(int n, int exp){
      |     ^~
a.cc:32:5: note: 'long long int po(long long int, long long int)' previously defined here
   32 | int po(int n, int exp){
      |     ^~
a.cc:137:5: error: redefinition of 'long long int n'
  137 | int n,m,p;
      |     ^
a.cc:38:5: note: 'long long int n' previously declared here
   38 | int n,m,p;
      |     ^
a.cc:137:7: error: redefinition of 'long long int m'
  137 | int n,m,p;
      |       ^
a.cc:38:7: note: 'long long int m' previously declared here
   38 | int n,m,p;
      |       ^
a.cc:137:9: error: redefinition of 'long long int p'
  137 | int n,m,p;
      |         ^
a.cc:38:9: note: 'long long int p' previously declared here
   38 | int n,m,p;
      |         ^
a.cc:138:13: error: redefinition of 'std::vector<long long int> g [2505]'
  138 | vector<int> g[N];
      |             ^
a.cc:39:13: note: 'std::vector<long long int> g [2505]' previously declared here
   39 | vector<int> g[N];
      |             ^
a.cc:139:33: error: redefinition of 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> > edge'
  139 | vector<pair<pair<int,int>,int>> edge;
      |                                 ^~~~
a.cc:40:33: note: 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> > edge' previously declared here
   40 | vector<pair<pair<int,int>,int>> edge;
      |                                 ^~~~
a.cc:140:13: error: redefinition of 'std::vector<long long int> vis'
  140 | vector<int> vis(N,0);
      |             ^~~
a.cc:41:13: note: 'std::vector<long long int> vis' previously declared here
   41 | vector<int> vis(N,0);
      |             ^~~
a.cc:141:5: error: redefinition of 'long long int dfs(long long int, long long int)'
  141 | int dfs(int i, int d)
      |     ^~~
a.cc:42:5: note: 'long long int dfs(long long int, long long int)' previously defined here
   42 | int dfs(int i, int d)
      |     ^~~
a.cc:110:12: error: redefinition of 'std::map<std::pair<long long int, long long int>, long long int> make_pair'
  110 | #define mp make_pair
      |            ^~~~~~~~~
a.cc:152:24: note: in expansion of macro 'mp'
  152 | map<pair<int,int>,int> mp;
      |                        ^~
a.cc:11:12: note: 'std::map<std::pair<long long int, long long int>, long long int> make_pair' previously declared here
   11 | #define mp make_pair
      |            ^~~~~~~~~
a.cc:53:24: note: in expansion of macro 'mp'
   53 | map<pair<int,int>,int> mp;
      |                        ^~
a.cc:153:8: error: redefinition of 'int main()'
  153 | signed main()
      |        ^~~~
a.cc:54:8: note: 'int main()' previously defined here
   54 | signed main()
      |        ^~~~