criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using GraphType = vector<vector<pair<int,int>>>;
template<typename Int>
bool Bellman_Ford(GraphType& Graph, vector<Int>& dist, int V, int start){
    dist[start] = 0;
    for(int v=0;v<V;++v){
        bool change = false;
        for(auto& e : Graph[v]){
            if(dist[v] == 1e18) continue;
            if(dist[e.first] > dist[v] + e.second){
                dist[e.first] = dist[v] + e.second;
                change = true;
            }
        }
        if(!circle) return false;
    }
    return true;
}

int main(){
    i64 N, M, P;
    cin >> N >> M >> P;
    vector<int> A(M), B(M);
    vector<i64> C(M);
    rep(i, M) cin >> A[i] >> B[i] >> C[i], A[i]--, B[i]--;

    vector<i64> C_inv(M);
    rep(i, M) C_inv[i] = -(C[i] - P);
    
    vector<bool> visited(N, false);
    {   
        vector<vector<int>> Graph(N);
        rep(i, M) Graph[B[i]].emplace_back(A[i]);
        function<void(int)> dfs = [&](int v){
            visited[v] = true;
            for(int nxt : Graph[v]){
                if(visited[nxt]) continue;
                dfs(nxt);
            }
        };
        dfs(N-1);
    }

    vector<vector<pair<int,int>>> Graph(N);
    vector<i64> dist(N, 1e18);

    rep(i, M){
        if(!visited[A[i]] || !visited[B[i]]) continue;
        Graph[A[i]].emplace_back(make_pair(B[i], C_inv[i]));
    }
    bool circle = Bellman_Ford(Graph, dist, N-1, 0);

    if(dist[N-1] == 1e18 || circle) cout << -1 << endl;
    else cout << max(-dist[N-1], (i64)0) << endl;
}

Compiler output:
a.cc: In function 'bool Bellman_Ford(GraphType&, std::vector<_Tp>&, int, int)':
a.cc:19:13: error: 'circle' was not declared in this scope
   19 |         if(!circle) return false;
      |             ^~~~~~
Language: C++

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#endif
//BEGIN CUT HERE
template<typename T>
struct BellmanFord{
  struct edge{
    int u,v;
    T w;
    edge(){}
    edge(int u,int v,T w):u(u),v(v),w(w){}
  };

  int n;
  vector< vector<int> > G;
  vector<int> used,reach;
  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,1){}

  vector<edge> es;
  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
    G[u].emplace_back(v);
  }

  vector<T> build(int from,int &neg_loop){
    const T INF = numeric_limits<T>::max();
    vector<T> ds(n,INF);
    ds[from]=0;
    for(int j=0;j<n;j++){
      bool update=0;
      for(auto e:es){
        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;
        if(ds[e.v]>ds[e.u]+e.w){
          ds[e.v]=ds[e.u]+e.w;
          update=1;
        }
      }
      if(!update) break;
      if(j==n-1){
        neg_loop=1;
        return INF;
      }
    }
    neg_loop=0;
    return ds;
  }

  void dfs(int v){
    if(used[v]) return;
    used[v]=1;
    for(int u:G[v]) dfs(u);
  }

  T shortest_path(int from,int to,int &neg_loop){
    for(int i=0;i<n;i++){
      fill(used.begin(),used.end(),0);
      dfs(i);
      reach[i]=used[to];
    }
    return build(from,neg_loop)[to];
  }
};
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  int n,m,p;
  cin>>n>>m>>p;
  BellmanFord<int> G(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G.add_edge(a,b,p-c);
  }
  int neg_loop;
  int res=G.shortest_path(0,n-1,neg_loop);
  if(neg_loop){
    cout<<-1<<endl;
    return 0;
  }
  cout<<max(-res,0)<<endl;
  return 0;
}
/*
  verified on 2019/08/10
  https://atcoder.jp/contests/abc137/tasks/abc137_e
*/
#endif


Compiler output:
a.cc: In instantiation of 'std::vector<_Tp> BellmanFord<T>::build(int, int&) [with T = int]':
a.cc:64:12:   required from 'T BellmanFord<T>::shortest_path(int, int, int&) [with T = int]'
   64 |     return build(from,neg_loop)[to];
      |            ^~~~~
a.cc:81:26:   required from here
   81 |   int res=G.shortest_path(0,n-1,neg_loop);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:45:16: error: could not convert 'INF' from 'const int' to 'std::vector<int>'
   45 |         return INF;
      |                ^~~
      |                |
      |                const int
Language: C++

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<int> graph[2500];
vector<int> weight[2500];
vector<long long int> cost(2500, 1000000000000);

int main(void){
    int N, M, P;
    cin >> N >> M >> P;
    
    for (int i = 0; i < M; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        graph[a-1].push_back(b-1);
        weight[a-1].push_back(P-w);
    }
    
    cost[0] = 0;
    int final_n = 0;
    for (int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < graph[i].size(); j++) {
                if (cost[graph[i][j]] > cost[i] + weight[i][j]) {
                    cost[graph[i][j]] = cost[i] + weight[i][j];
                    
                    if (k != N-1 && graph[i][j] == N-1)
                        final_n = cost[graph[i][j]];
                    else if (k == N-1 && graph[i][j] == N-1 && final_n != cost[graph[i][j]]) { 
                        cout << -1 << endl;
                        exit(0);
                    }
                }
            }
        }
    }

    if (cost[N-1] >= 0)
        cout << 0 << endl;
    else
        cout << -cost[N-1] << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:43:36: error: expected '}' at end of input
   43 |         cout << -cost[N-1] << endl;
      |                                    ^
a.cc:10:15: note: to match this '{'
   10 | int main(void){
      |               ^
Language: C++

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<int> graph[2500];
vector<int> weight[2500];
vector<long long int> cost(2500, 1000000000);

int main(void){
    int N, M, P;
    cin >> N >> M >> P;
    
    for (int i = 0; i < M; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        graph[a-1].push_back(b-1);
        weight[a-1].push_back(P-w);
    }
    
    cost[0] = 0;
    int final_n = 0;
    for (int k = 0; k <= N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < graph[i].size(); j++) {
                if (cost[graph[i][j]] > cost[i] + weight[i][j]) {
                    cost[graph[i][j]] = cost[i] + weight[i][j];
                    
                    if (k != N && graph[i][j] == N-1)
                        final_n = cost[graph[i][j]];
                    else if (k == N && graph[i][j] == N-1 && final_n != cost[graph[i][j]]) { 
                        cout << -1 << endl;
                        exit(0);
                    }
                }
            }
        }
    }
    
    if (cost[N-1] == 1000000000)
        cout << -1 << endl;
    else if (cost[N-1] >= 0)
        cout << 0 << endl;
    else
        cout << -cost[N-1] << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:45:36: error: expected '}' at end of input
   45 |         cout << -cost[N-1] << endl;
      |                                    ^
a.cc:10:15: note: to match this '{'
   10 | int main(void){
      |               ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define NINF -1e17

struct ed{
  int from;
  int to;
  long cost;
};

int main(){
  int n,m,p;
  cin >> n >> m >> p;
  vector<ed> eds(m);
  rep(i,m){
    cin >> eds.at(i).from >> eds.at(i).to >> eds.at(i).cost;
    eds.at(i).from--;
    eds.at(i).to--;
    eds.at(i).cost -= p;
  }
  vector<long> d(n,NINF);
  d.at(0) = 0;
  rep(i,n){
    rep(j,m){
      struct ed e = eds.at(j);
      //if(d.at(e.from) == NINF) continue;
      
      if(d.at(e.to) < d.at(e.from) + e.cost){
        d.at(e.to) = d.at(e.from) + e.cost;
        if(i == n-1 && e.to == n-1){
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  long x = 0;
  if((d.at(n-1) == NINF) x = 4/0;
  cout << max(d.at(n-1),x) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:25: error: expected ';' before 'x'
   48 |   if((d.at(n-1) == NINF) x = 4/0;
      |                         ^~
      |                         ;
a.cc:49:35: error: expected ')' before ';' token
   49 |   cout << max(d.at(n-1),x) << endl;
      |                                   ^
      |                                   )
a.cc:48:5: note: to match this '('
   48 |   if((d.at(n-1) == NINF) x = 4/0;
      |     ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;

vector<int>to[2505];
vector<int>rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v){
  if(reachableFrom1[v])return;
  reachableFrom1[v]=true;
  for(int u:to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(reachableToN[v])return;
  reachableToN[v]=true;
  for(int u:rto[v]){
    rdfs(u);
  }
}

int main(){
  int n,m,p;
  cin>>n>>m>>p;
  vector<tuple<int,int,int>>edges;
  rep(i,m){
    int a,b,c;
    --a;--b;
    c-=p;
    c=-c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(0);
  rep(i,n)ok[i]=reachableFrom1[i]&reachableToN[i];
  {//bellman-ford
    vector<int>d(n,INF);
    d[0]=0;
    bool upd=true;
    int step=0;
    while (upd){
      upd=false;
      rep(i,n){
        int a,b,c;
        tie(a,b,c)=edges[i];
        if(!ok[a])continue;
        if(!ok[b])continue;
        int newD=d[a]+c;
        if (newD<d[b]){
          upd=true;
          d[b]=newD;
        }
      }
      step++;
      if (step>n){
        puts("-1");
        return 0;
      }
    }
    int ans=-d[n-a];
    ans=max(ans,0);    
    cout<<ans<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:68:18: error: 'a' was not declared in this scope
   68 |     int ans=-d[n-a];
      |                  ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;

vector<int>to[2505];
vector<int>rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v){
  if(reachableFrom1[v])return;
  reachableFrom1[v]=true;
  for(int u:to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(reachableoN[v])return;
  reachableToN[v]=true;
  for(int u:rto[v]){
    rdfs(u);
  }
}

int main(){
  int n,m,p;
  cin>>n>>m>>p;
  vector<tuple<int,int,int>>edges;
  rep(i,m){
    int a,b,c;
    --a;--b;
    c-=p;
    c=-c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(0);
  rep(i,n)ok[i]=reachableFrom1[i]&reachableToN[i];
  {//bellman-ford
    vector<int>d(n,INF);
    d[0]=0;
    bool upd=true;
    int step=0;
    while (upd){
      upd=false;
      rep(i,n){
        int a,b,c;
        tie(a,b,c)=edges[i];
        if(!ok[a])continue;
        if(!ok[b])continue;
        int newD=d[a]+c;
        inf (newD<d[b]){
          upd=true;
          d[b]=newD;
        }
      }
      step++;
      if (step>n){
        puts("-1");
        return 0;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'void rdfs(int)':
a.cc:21:6: error: 'reachableoN' was not declared in this scope; did you mean 'reachableToN'?
   21 |   if(reachableoN[v])return;
      |      ^~~~~~~~~~~
      |      reachableToN
a.cc: In function 'int main()':
a.cc:57:9: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   57 |         inf (newD<d[b]){
      |         ^~~
      |         ynf
a.cc:69:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   69 |   cout<<ans<<endl;
      |         ^~~
      |         abs
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;

vector<int>to[2505];
vector<int>rto[2505];
bool reachableFrom1[2505];
bool reachableFrom1[2505];
bool ok[2505];

void dfs(int v){
  if(reachableFrom1[v])return;
  reachableFrom1[v]=true;
  for(int u:to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(reachableoN[v])return;
  reachableToN[v]=true;
  for(int u:rto[v]){
    rdfs(u);
  }
}

int main(){
  int n,m,p;
  cin>>n>>m>>p;
  vector<tuple<int,int,int>>edges;
  rep(i,m){
    int a,b,c;
    --a;--b;
    c-=p;
    c=-c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(0);
  rep(i,n)ok[i]=reachableFrom1[i]&reachableToN[i];
  {//bellman-ford
    vector<int>d(n,INF);
    d[0]=0;
    bool upd=true;
    int step=0;
    while (upd){
      upd=false;
      rep(i,n){
        int a,b,c;
        tie(a,b,c)=edges[i];
        if(!ok[a])continue;
        if(!ok[b])continue;
        int newD=d[a]+c;
        inf (newD<d[b]){
          upd=true;
          d[b]=newD;
        }
      }
      step++;
      if (step>n){
        puts("-1");
        return 0;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc:10:6: error: redefinition of 'bool reachableFrom1 [2505]'
   10 | bool reachableFrom1[2505];
      |      ^~~~~~~~~~~~~~
a.cc:9:6: note: 'bool reachableFrom1 [2505]' previously declared here
    9 | bool reachableFrom1[2505];
      |      ^~~~~~~~~~~~~~
a.cc: In function 'void rdfs(int)':
a.cc:21:6: error: 'reachableoN' was not declared in this scope; did you mean 'reachableFrom1'?
   21 |   if(reachableoN[v])return;
      |      ^~~~~~~~~~~
      |      reachableFrom1
a.cc:22:3: error: 'reachableToN' was not declared in this scope; did you mean 'reachableFrom1'?
   22 |   reachableToN[v]=true;
      |   ^~~~~~~~~~~~
      |   reachableFrom1
a.cc: In function 'int main()':
a.cc:43:35: error: 'reachableToN' was not declared in this scope; did you mean 'reachableFrom1'?
   43 |   rep(i,n)ok[i]=reachableFrom1[i]&reachableToN[i];
      |                                   ^~~~~~~~~~~~
      |                                   reachableFrom1
a.cc:57:9: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   57 |         inf (newD<d[b]){
      |         ^~~
      |         ynf
a.cc:69:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   69 |   cout<<ans<<endl;
      |         ^~~
      |         abs
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;

vector<int>to[2505];
vector<int>rto[2505];
bool reachableFrom1[2505];
bool reachableFrom1[2505];
bool ok[2505];

void dfs(int v){
  if(reachableFrom1[v])return;
  reachableFrom1[v]=true;
  for(int u:to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(reachableoN[v])return;
  reachableToN[v]=true;
  for(int u:rto[v]){
    rdfs(u);
  }
}

int main(){
  int n,m,p;
  cin>>n>>m>>p;
  vector<tuple<int,int,int>>edges;
  rep(i,m){
    int a,b,c;
    --a;--b;
    c-=p;
    c=-c;
    

  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc:10:6: error: redefinition of 'bool reachableFrom1 [2505]'
   10 | bool reachableFrom1[2505];
      |      ^~~~~~~~~~~~~~
a.cc:9:6: note: 'bool reachableFrom1 [2505]' previously declared here
    9 | bool reachableFrom1[2505];
      |      ^~~~~~~~~~~~~~
a.cc: In function 'void rdfs(int)':
a.cc:21:6: error: 'reachableoN' was not declared in this scope; did you mean 'reachableFrom1'?
   21 |   if(reachableoN[v])return;
      |      ^~~~~~~~~~~
      |      reachableFrom1
a.cc:22:3: error: 'reachableToN' was not declared in this scope; did you mean 'reachableFrom1'?
   22 |   reachableToN[v]=true;
      |   ^~~~~~~~~~~~
      |   reachableFrom1
a.cc: In function 'int main()':
a.cc:39:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |   cout<<ans<<endl;
      |         ^~~
      |         abs
a.cc:41:2: error: expected '}' at end of input
   41 | }
      |  ^
a.cc:28:11: note: to match this '{'
   28 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


typedef long long ll;
typedef pair<ll, ll> P;


ll dist[2600];
int main()
{
  ll N, M, P; cin >> N >> M >> P;
  vector<vector<pair<ll, ll>>> v(N);
  REP(i, M) {
    ll a, b, c; cin >> a >> b >> c;
    a--; b--;
    v[a].PB(MP(b, -(c-P)));
  }

  REP(i, 2600) dist[i] = LLINF;
  dist[0] = 0;
  REP(i, N - 1) {
    REP(j, N) {
      if (dist[j] == LLINF) continue;
      for (auto e : v[j]) {
        if (dist[e.first] > dist[j] + e.second) {
          dist[e.first] = dist[j] + e.second;
        }
      }
    }
  }

  vector<bool> ng(N, false);
  REP(i, N - 1) {
    REP(j, N) {
      if (dist[j] == LLINF) continue;
      for (auto e : v[j]) {
        if (dist[e.first] > dist[j] + e.second) {
          dist[e.first] = dist[j] + e.second;
          ng[e.first] = true;
        }
        if (ng[j]) ng[e.first] = true;
      }
    }
  }
  if (ans != dist[N - 1]) cout << "-1" << endl;
  else cout << max(0LL, -ans) << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:7: error: 'ans' was not declared in this scope; did you mean 'abs'?
   65 |   if (ans != dist[N - 1]) cout << "-1" << endl;
      |       ^~~
      |       abs
Language: C++

#include <bits/stdc++.h>
#define int long long

using namespace std;
struct edge
{
    int a,b,c;
};
edge s[5005];
int dp[2505];
int n,m,p;
int ans=0;
void solve()
{
    for (int i = 0; i < n-1; ++i) {
        for (int j = 0; j < m; ++j) {
            if(dp[s[j].a]!=1e17)
            {
                dp[s[j].b]=min(dp[s[j].b],dp[s[j].a]+s[j].c);
            }
        }
    }

    int k=dp[n-1];
    int z=1e5;
    z*=5
    for (int i = 0; i < z; ++i) {
        for (int j = 0; j < m; ++j) {
            if(dp[s[j].b]!=1e17)
            {
                dp[s[j].b]=min(dp[s[j].b],dp[s[j].a]+s[j].c);
            }
        }
    }

    if(k>dp[n-1])
    {
        ans=-(1e17);
    }
    else
    {
        ans=-dp[n-1];
    }

}


signed main()
{
    cin>>n>>m>>p;

    fill_n(dp,2505,1e17);
    dp[0]=0;
    int x,y,z;
    for (int i = 0; i < m; ++i) {
        cin>>x>>y>>z;
        x--;
        y--;
        z=p-z;
        s[i].a=x;
        s[i].b=y;
        s[i].c=z;
    }
    solve();
    if(ans==-1e17)
        cout<<-1;
    else
        cout<<max(0LL,ans);

}

Compiler output:
a.cc: In function 'void solve()':
a.cc:26:9: error: expected ';' before 'for'
   26 |     z*=5
      |         ^
      |         ;
   27 |     for (int i = 0; i < z; ++i) {
      |     ~~~  
a.cc:27:21: error: 'i' was not declared in this scope
   27 |     for (int i = 0; i < z; ++i) {
      |                     ^
Language: C++

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef Long Long ll;

const int INF = 1001001001;

vector<int> to[2505];
vector<int> rto[2505];
int reachableFrom1[2505];
int reachableFromN[2505];
int ok[2505];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int u: to[v]) {
        dfs(u);
    }
}

void r_dfs(int v) {
    if (reachableFromN[v]) return;
    reachableFromN[v] = true;
    for (int u: to[v]) {
        rdfs(u);
    }
}

int main(void) {
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c)
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    r_dfs(n - 1);
    rep(i, n) ok[i] = reachableFrom1[i] & reachableFromN[i];
    { // bellman-ford
        vector<int> d(n, INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            rep(i, m) {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;
                int newD = d[a] + c;
                if (newD < d[b]) {
                    upd = true;
                    d[b] = newdD;
                }
            }
            step++;
            if (step > n) {
                puts("-1");
                return 0;
            }
        }

        int ans = -d[n - 1];
        ans = max(ans, 0);
        cout << ans << endl;
    }

    return 0;
}

Compiler output:
a.cc:5:9: error: 'Long' does not name a type; did you mean 'long'?
    5 | typedef Long Long ll;
      |         ^~~~
      |         long
a.cc: In function 'void r_dfs(int)':
a.cc:27:9: error: 'rdfs' was not declared in this scope; did you mean 'r_dfs'?
   27 |         rdfs(u);
      |         ^~~~
      |         r_dfs
a.cc: In function 'int main()':
a.cc:42:36: error: expected ';' before 'to'
   42 |         edges.emplace_back(a, b, c)
      |                                    ^
      |                                    ;
   43 |         to[a].push_back(b);
      |         ~~                          
a.cc:64:28: error: 'newdD' was not declared in this scope; did you mean 'newD'?
   64 |                     d[b] = newdD;
      |                            ^~~~~
      |                            newD
Language: C++

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef Long Long
ll;

const int INF = 1001001001;

vector<int> to[2505];
vector<int> rto[2505];
int reachableFrom1[2505];
int reachableFromN[2505];
int ok[2505];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int u: to[v]) {
        dfs(u);
    }
}

void r_dfs(int v) {
    if (reachableFromN[v]) return;
    reachableFromN[v] = true;
    for (int u: to[v]) {
        rdfs(u);
    }
}

int main(void) {
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c)
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    r_dfs(n - 1);
    rep(i, n) ok[i] = reachableFrom1[i] & reachableFromN[i];
    { // bellman-ford
        vector<int> d(n, INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            rep(i, m) {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;
                int newD = d[a] + c;
                if (newD < d[b]) {
                    upd = true;
                    d[b] = newdD;
                }
            }
            step++;
            if (step > n) {
                puts("-1");
                return 0;
            }
        }

        int ans = -d[n - 1];
        ans = max(ans, 0);
        cout << ans << endl;
    }

    return 0;
}

Compiler output:
a.cc:5:9: error: 'Long' does not name a type; did you mean 'long'?
    5 | typedef Long Long
      |         ^~~~
      |         long
a.cc: In function 'void r_dfs(int)':
a.cc:28:9: error: 'rdfs' was not declared in this scope; did you mean 'r_dfs'?
   28 |         rdfs(u);
      |         ^~~~
      |         r_dfs
a.cc: In function 'int main()':
a.cc:43:36: error: expected ';' before 'to'
   43 |         edges.emplace_back(a, b, c)
      |                                    ^
      |                                    ;
   44 |         to[a].push_back(b);
      |         ~~                          
a.cc:65:28: error: 'newdD' was not declared in this scope; did you mean 'newD'?
   65 |                     d[b] = newdD;
      |                            ^~~~~
      |                            newD
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;
const int INFTY = 3e8;

vector<map<int, int>> edge;
vi path;
vector<bool> seen, finished;

void dfs(int v) {
  seen[v] = true;

  for (auto p : edge[p]) {
    auto &nv = p.first;
    auto &coin = p.second;

    if (path[nv] == INFTY) continue;

    if (path[v] == INFTY) {
      path[nv] == INFTY;
      dfs(nv);
    }

    else if (path[nv] < path[v] + coin) {
      if (seen[nv] && !finished[nv]) path[nv] = INFTY;
      else path[nv] = path[v] + coin;
      dfs(nv);
    }
  }

  finished[v] = true;
  return;
}

void solve() {
  int N, M, P; cin >> N >> M >> P;
  edge.resize(N);
  int a, b, c;
  rep(i,M) {
    cin >> a >> b >> c; --a; --b; c-=P;
    if (!edge[a].count(b)) edge[a][b] = c;
    else edge[a][b] = max(edge[a][b], c);
  }

  path.assign(N, -INFTY);
  seen.assign(N, false);
  finished.assign(N, false);

  dfs(0);

  int ans = path[N-1];
  if (path[N-1] == INFTY) ans = -1;
  if (path[N-1] < 0) ans = 0;
  cout << ans << endl;
  return;
}

int main() {
  solve();
  return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:20:22: error: 'p' was not declared in this scope
   20 |   for (auto p : edge[p]) {
      |                      ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

using ll=long long;

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(e,E) for(const auto &e:E)

using namespace std;

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=from[j];
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
			if(i>=5100&&to[e.first]>from[e.first]) to[e.first]=1LL<<60;
		}
		
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	if(ma>=1LL<<59) ma=-1;
	cout<<ma<<endl;
	
	
}


Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

using ll=long long;

#define FOR(i,n) for(int i=0;i<n;i++)

using namespace std;

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=from[j];
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
			if(i>=5100&&to[e.first]>from[e.first]) to[e.first]=1LL<<60;
		}
		
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	if(ma>=1LL<<59) ma=-1;
	cout<<ma<<endl;
	
	
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:30:54: error: 'e' was not declared in this scope
   30 |                 FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
      |                                                      ^
a.cc:30:49: error: 'FORR' was not declared in this scope; did you mean 'FOR'?
   30 |                 FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
      |                                                 ^~~~
      |                                                 FOR
Language: C++

#include<iostream>
#include<vector>

#define FOR(i,n) for(int i=0;i<n;i++)

using namespace std;

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=from[j];
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
			if(i>=5100&&to[e.first]>from[e.first]) to[e.first]=1LL<<60;
		}
		
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	if(ma>=1LL<<59) ma=-1;
	cout<<ma<<endl;
	
	
}


Compiler output:
a.cc:9:1: error: 'll' does not name a type
    9 | ll from[2500],to[2500];
      | ^~
a.cc: In function 'void solve()':
a.cc:22:18: error: 'from' was not declared in this scope
   22 |         FOR(i,N) from[i]=-(1LL<<60);
      |                  ^~~~
a.cc:23:9: error: 'from' was not declared in this scope
   23 |         from[0]=0;
      |         ^~~~
a.cc:24:9: error: 'll' was not declared in this scope; did you mean 'l'?
   24 |         ll ma=-1LL<<60;
      |         ^~
      |         l
a.cc:26:26: error: 'to' was not declared in this scope; did you mean 'tm'?
   26 |                 FOR(j,N) to[j]=from[j];
      |                          ^~
      |                          tm
a.cc:27:54: error: 'e' was not declared in this scope
   27 |                 FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
      |                                                      ^
a.cc:27:49: error: 'FORR' was not declared in this scope; did you mean 'FOR'?
   27 |                 FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
      |                                                 ^~~~
      |                                                 FOR
a.cc:32:17: error: 'ma' was not declared in this scope
   32 |                 ma=max(ma,to[N-1]);
      |                 ^~
a.cc:32:27: error: 'to' was not declared in this scope; did you mean 'tm'?
   32 |                 ma=max(ma,to[N-1]);
      |                           ^~
      |                           tm
a.cc:35:9: error: 'ma' was not declared in this scope
   35 |         ma=max(ma,0LL);
      |         ^~
Language: C++

#include<iostream >
#include<vector>

#define FOR(i,n) for(int i=0;i<n;i++)

using namespace std;

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=from[j];
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
			if(i>=5100&&to[e.first]>from[e.first]) to[e.first]=1LL<<60;
		}
		
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	if(ma>=1LL<<59) ma=-1;
	cout<<ma<<endl;
	
	
}

Compiler output:
a.cc:1:9: fatal error: iostream : No such file or directory
    1 | #include<iostream >
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,int> tup;

const int N = (int)2500;
const int M = (int)5000;

const tup NOL = make_pair((long long)-1e15, (int)1e12);

tup maxx(tup a, tup b, long long p) {
    if (a.first - b.first >= (long long)(a.second - b.second) * p) {
        return a;
    } else {
        return b;
    }
}

pair< pair<int,int> , long long> edgeList[M+5];
tup resa[N+5];
tup resb[N+5];

int main() {
    for (int i=0; i<N+3; i++) {
        resa[i] = resb[i] = NOL;
    }
    resa[1] = resb[1] = make_pair(0,0);

    int n,m,p; scanf("%d %d %d", &n, &m, &p);
    for (int i=0; i<m; i++) {
        int u,v,w; scanf("%d %d %d", &u, &v, &w);
        edgeList[i].first = make_pair(u,v);
        edgeList[i].second = w;
    }

    for (int iteration=1; iteration<=2; iteration++) {
        for (int xxx=0; xxx<10*n; xxx++) {
            for (int i=0; i<m; i++) {
                int u = edgeList[i].first.first;
                int v = edgeList[i].first.second;
                int w = edgeList[i].second;

                if (resa[u] != NOL) {
                    tup temp = make_pair(
                        resa[u].first + (long long)w,
                        resa[u].second + 1
                    );

                    resa[v] = maxx(resa[v], temp, p);
                }
            }
        }

        if (iteration == 1) {
            for (int i=0; i<N+3; i++) {
                resb[i] = resa[i];
            }
        }
    }

    if (resa[n] != resb[n]) {
        printf("-1\n");
    } else {
        printf("%lld\n", max((long long)0, res_a));
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:44: error: 'res_a' was not declared in this scope; did you mean 'resa'?
   64 |         printf("%lld\n", max((long long)0, res_a));
      |                                            ^~~~~
      |                                            resa
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vp;

void bf(vi e[], int n, int dis[]) {
    for (int i = 0; i < n; i++) {
        for (int x = 0; x < n; x++) {
            for (pii y : e[x]) {
                dis[y.second] = max(dis[y.second], dis[x] + y.first);
            }
        }
    }
}

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vp e[n];
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--, c -= p;
        e[a].push_back({c, b});
    }

    int dis[n];
    fill(dis, dis+n, -3e8);
    dis[0] = 0;
    bf(e, n, dis);

    int disn = dis[n-1];
    bf(e, n, dis);

    cout << (dis[n-1] == disn ? max(0, disn) : -1) << endl;

    return 0;
}

Compiler output:
a.cc:11:6: error: variable or field 'bf' declared void
   11 | void bf(vi e[], int n, int dis[]) {
      |      ^~
a.cc:11:9: error: 'vi' was not declared in this scope; did you mean 'vp'?
   11 | void bf(vi e[], int n, int dis[]) {
      |         ^~
      |         vp
a.cc:11:17: error: expected primary-expression before 'int'
   11 | void bf(vi e[], int n, int dis[]) {
      |                 ^~~
a.cc:11:24: error: expected primary-expression before 'int'
   11 | void bf(vi e[], int n, int dis[]) {
      |                        ^~~
a.cc: In function 'int main()':
a.cc:35:5: error: 'bf' was not declared in this scope
   35 |     bf(e, n, dis);
      |     ^~
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#include<queue>
#include<map>
#include<climits>
#include<tuple>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;

static const int MAX = 2500;
static const int MMAX = 5001;
static const int INFTY = (1LL << 29);

int n, m, p;
int pre[MAX], self[MAX];
lli d[MAX];
// vector<tuple<int, int, int>> edges;
vector<pair<int, int>> edges(MMAX);
vector<lli> weight;



bool bellman_ford(int s) {
  d[s] = 0;
  rep(i,n) {
    rep(j, m) {
      int u = edges[j].first;
      int v = edges[j].second;
      int w = weight[j];
      if (d[u] == INFTY) continue;
      else if (d[v] == INFTY) d[v] = d[u] + w;
      else if(d[v] > d[u] + w) {
        if (u == v) {
          d[v] = (-1)*INFTY;
        } else {
          if (d[u] == (-1)*INFTY) {
            if (v == n-1) return false;
            else d[v] = (-1)*INFTY;
          } else {
            d[v] = d[u] + w;
          }
          pre[v] = u;
        }
      }
    }
  }
  int d2 = d;
  rep(i,n) {
    rep(j, m) {
      int u = edges[j].first;
      int v = edges[j].second;
      int w = weight[j];
      if (d[u] == INFTY) continue;
      else if (d[v] == INFTY) d[v] = d[u] + w;
      else if(d[v] > d[u] + w) {
        if (u == v) {
          d[v] = (-1)*INFTY;
        } else {
          if (d[u] == (-1)*INFTY) {
            if (v == n-1) return false;
            else d[v] = (-1)*INFTY;
          } else {
            d[v] = d[u] + w;
          }
          pre[v] = u;
        }
      }
    }
  }
  if (d2[n-1] != d[n-1]) return false;
  // rep(j, m){
  //   int u = edges[j].first;
  //   int v = edges[j].second;
  //   int w = weight[j];
  //   if ((d[v] > d[u] + w)&&(u != v) ) {
  //     return false;
  //   }
  // }
  return true;
}
  // for(auto e : edges) {
  //   int u = get<0>(e);
  //   int v = get<1>(e);
  //   int w = get<2>(e);
  //   if (d[v] > d[u] + w) {
  //     return -1;
  //   }
  // }
//   return d[n-1];
// }

int main() {
  int a, b, c;
  cin >> n >> m >> p;
  rep(i, n) {
    d[i] = (i == 0) ? 0 : INFTY; // initialization
    pre[i] = NIL;
  }

  rep(i, m) {
    scanf("%d %d %d", &a, &b, &c);
    a--; b--; c = p - c;
    // edges[i] = make_tuple(a, b, c);
    edges[i] = make_pair(a, b);
    weight.push_back(c);
  }

  bool res = bellman_ford(0);
  // rep(i,n) {
  //   cout << d[i] << " ";
  // }
  // cout << endl;
  if (res) {
    if (-d[n-1] < 0) {
      cout << 0 << endl;
    } else {
      cout << -d[n-1] << endl;
    }
  } else {
    cout << -1 << endl;
  }
}


Compiler output:
a.cc: In function 'bool bellman_ford(int)':
a.cc:53:12: error: invalid conversion from 'lli*' {aka 'long long int*'} to 'int' [-fpermissive]
   53 |   int d2 = d;
      |            ^
      |            |
      |            lli* {aka long long int*}
a.cc:76:9: error: invalid types 'int[int]' for array subscript
   76 |   if (d2[n-1] != d[n-1]) return false;
      |         ^
Language: C++

/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, p;
    int a[5100];
    int b[5100];
    int c[5100];
    cin >> n >> m >> p;
    rep(i, m) cin >> a[i] >> b[i] >> c[i];
    rep(i, m) a[i]--;
    rep(i, m) b[i]--;
    rep(i, m) c[i] = -(c[i] - p);

    vector<vector<int>> vec(m);
    rep(i, m) vec[i].push_back(m);

    int d[3000] = {INF};
    d[0] = 0;

    rep(i, n - 1) {
        rep(j, m) {
            if (d[b[j]] > d[a[j]] + c[j])
                d[b[j]] = d[a[j]] + c[j];
        }
    }

    int res = -d[n - 1];

    rep(i, n - 1) {
        rep(j, m) {
            if (d[b[j]] > d[a[j]] + c[j])
                d[b[j]] = d[a[j]] + c[j];
        }
    }

    if (res != -d[n - 1])
        print(-1)
    else
        print(max(0, res));



    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:108:5: error: expected ';' before 'else'
  108 |     else
      |     ^~~~
Language: C

#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const ll infll = (1ll<<60);
const int mod = 1000000007;
using namespace std;

struct edge{
	int from;
	int to;
	ll cost;
};

vector<edge> graph;

vector<int> checkgraph[3000];
bool besucht[3000];

void checkdfs( int punkt ){
	if( besucht[punkt] ) return;
	besucht[punkt] = true;
	for( auto nextp : checkgraph[punkt] ){
		checkdfs( nextp );
	}
}

int main(){
	int n, m; ll p; cin >> n >> m >> p;
	const int s = 0, g = n-1;
	for( int i = 0; i < m; ++i ){
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		graph.push_back( (edge){a, b, -(c-p)} );
		checkgraph[a].push_back(b);
	}
	checkdfs(0); 
	vector<ll> d(n);
	fill_n( d.begin(), n, infll );
	d[s] = 0;
	int k = n-1;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			d[e.to] = min(d[e.to], d[e.from]+e.cost);
		}
	}
    // Siehe auch: https://img.atcoder.jp/abc061/editorial.pdf
    // 解説が微妙に誤りで，「負閉路の長さが最大で N であるため…」と書いてあるが
    // 負閉路を検出さえすれば次の伝搬フェーズでゴールに正しく negativ は伝搬する
    // なので次のループはこの 1 回のみでよい 
	bool negativ[n];
	fill_n( negativ, n, false );
	for( auto e : graph ){
		if( !besucht[e.from] ) continue;
		if( d[e.to] > d[e.from]+e.cost ){
			d[e.to] = d[e.from]+e.cost;
			negativ[e.to] = true;
		}
	}
	k = n;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			if( negativ[e.from] ) negativ[e.to] = true;
		}
	}
	if( negativ[g] ) cout << -1 << endl;
	else cout << max(0ll, -d[g]) << endl;
	return 0;
}

/*

基本方針: ベルマンフォードを動かす

負閉路について:
	ベルマンフォードは負の閉路がどこかにあることを検出できるが，そのままでは
	スタートからゴールに行く過程に負閉路があるかどうかはわからない
	・例 3 のノード 2 のような例（スタートから行けるがゴールには行けない）
		→	N-1 回ループを回したあと N 回目を回して，変化があった（⇔負閉路が存在する）ところから
			辿ってゴールに行けるかどうかを確かめる
	・例 3 のノード 3 のような例（ゴールには行けるがスタートからは行けない）
		→	グラフを DFS してたどり着く可能性のある場所を列挙しておく 

嘘解法: たくさん回してゴールの最短距離が更新されたら過程に負の回路がある
		これは正しくない（次のような例では C が更新されないが B で無限にループすることで最短距離を更新できる）
		　B ↩ -10
	-10　↗　 ↘ -10
		A ─→ C
		　-999

*/

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
using namespace std;

class BellmanFord
{
	class Edge {
		int from, to; // 2端点のインデックス
		int weight; // コスト

	public :
		Edge(int n, int m, int w) {
			from = n;
			to = m;
			weight = w;
		}
		int GetFrom() { return from; }
		int GetTo() { return to; }
		int GetWeight() { return weight; }
	};

	int node_num;
	vector<Edge> edges;
	int *distances;
	int start;
	int end;

public:
	BellmanFord(int n, int s, int e) {
		node_num = n;
		start = s;
		end = e;
		distances = new int[n];
	}

	~BellmanFord() {
		delete[] distances;
	}

	void AddEdge(int from, int to, int weight) {
		Edge edge(from, to, weight);
		edges.push_back(edge);
	}

	int ShortestPath(bool &has_roop) {
		// initialise
		for (int i = 0; i < node_num; i ++) {
			distances[i]  = (i == start)? 0 : INT_MAX;
		}
		has_roop = false;

		vector<Edge>::iterator itr, itr_end = edges.end();
		for (int i = 0; i < node_num; i ++) {
			for (itr = edges.begin(); itr != itr_end; itr ++) {
				int from_cost = distances[itr->GetFrom()];
				int to_cost = distances[itr->GetTo()];

				if (from_cost == INT_MAX) continue; // 1度も訪れていない
				int new_dist = from_cost + itr->GetWeight();

				if (new_dist < to_cost) {
					distances[itr->GetTo()] = new_dist;
					if (i == node_num-1) {
						// ループがなければ、1回のコスト更新で1つの頂点の経路が確定
						// つまり、node_num-1回ですべての頂点の経路の最小値が決まる
						// node_num回目の更新ができるとすると、ループがある
						has_roop = true;
						break;
					}
				}
			}
		}

		return distances[end];
	}
};

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	BellmanFord bellman(n, 0, n-1);

	int a, b, c;
	for (int i = 0; i < m; i ++) {
		cin >> a >> b >> c;
		c = c - p;
		a = a-1;
		b = b-1;
		// 最短経路を求めるアルゴリズムなので-1をかける
		c *= -1;
		bellman.AddEdge(a, b, c);
	}

	bool has_roop = false;
	int dist = bellman.ShortestPath(has_roop);
	if (has_roop) cout << "-1" << endl;
	else {
		dist *= -1; // スコアの符号を戻す
		cout << dist << endl;
	}

	return 0;
}

Compiler output:
a.cc: In member function 'int BellmanFord::ShortestPath(bool&)':
a.cc:48:59: error: 'INT_MAX' was not declared in this scope
   48 |                         distances[i]  = (i == start)? 0 : INT_MAX;
      |                                                           ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <vector>
  +++ |+#include <climits>
    3 | using namespace std;
a.cc:58:50: error: 'INT_MAX' was not declared in this scope
   58 |                                 if (from_cost == INT_MAX) continue; // 1度も訪れていない
      |                                                  ^~~~~~~
a.cc:58:50: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
Language: C++

#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
using namespace std;

typedef struct edge {
	int a, b, cost;


};

int main() {

	int n,m,v[2501],mm=INT_MIN,p,aa,bb,costt;
	vector<edge>vv;
	cin >> n>>m>>p;

	for (int i = 0;i <= n;i++)
		v[i] = mm;
	v[1] = 0;
	for (int i = 0;i < m;i++) {
		cin >> aa >> bb >> costt;
		edge e;
		e.a = aa;
		e.b = bb;
		e.cost = costt-p;
		vv.push_back(e);
	}
	for (int i = 1;i < n;i++) {
		for (auto e : vv) {
			if (v[e.a] + e.cost > v[e.b])
				v[e.b] = v[e.a] + e.cost;
		}
	}

	int ok = 0;
	for (auto e : vv) {
		if (v[e.a] + e.cost > v[e.b])
		{
			v[e.b] = v[e.a] + e.cost;
			if (e.b == n)
			{
				ok = 1;
				break;
			}
		}
	}
	if (v[n] <= 0)
		cout << 0;
	else {
		if (ok == 1)
			cout << -1;
		else
			cout << v[n];
	}
	return 0;
}

Compiler output:
a.cc:9:1: warning: 'typedef' was ignored in this declaration
    9 | typedef struct edge {
      | ^~~~~~~
a.cc: In function 'int main()':
a.cc:17:28: error: 'INT_MIN' was not declared in this scope
   17 |         int n,m,v[2501],mm=INT_MIN,p,aa,bb,costt;
      |                            ^~~~~~~
a.cc:7:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    6 | #include<stdint.h>
  +++ |+#include <climits>
    7 | using namespace std;
a.cc:19:22: error: 'p' was not declared in this scope
   19 |         cin >> n>>m>>p;
      |                      ^
a.cc:25:24: error: 'aa' was not declared in this scope
   25 |                 cin >> aa >> bb >> costt;
      |                        ^~
a.cc:25:30: error: 'bb' was not declared in this scope
   25 |                 cin >> aa >> bb >> costt;
      |                              ^~
a.cc:25:36: error: 'costt' was not declared in this scope
   25 |                 cin >> aa >> bb >> costt;
      |                                    ^~~~~