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

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

template< typename T>
struct edge { 
   int from, to; 
   T cost; 
   edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template< typename T>
using EDGE = vector< edge< T > >;

template< typename T>
vector< T > bellman_ford(EDGE< T > &es, 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 : es) {
         if (dist[e.from] == INF) continue;
         dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
      }
   }
   for (auto & e : es) {
      if (dist[e.from] == INF) continue;
      if (dist[e.from] + e.cost < dist[e.to]) return vector< T >();
   }
   return dist;
}

const int MAXN = 2501;
bool used1[MAXN];
bool used2[MAXN];
vector<int> G1[MAXN], G2[MAXN];

void bfs1(int s) {
   used1[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G1[cur]) {
         if (used1[g]) continue;
         used1[g] = true;
         q.push(g);
      }
   }
}

void bfs2(int s) {
   used2[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G2[cur]) {
         if (used2[g]) continue;
         used2[g] = true;
         q.push(g);
      }
   }
}

int main() {
   int N, M, P;
   cin >> N >> M >> P;
   int A[M], B[M], C[M];
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i] >> C[i];
      A[i]--;
      B[i]--;
      C[i] = -1 * (C[i] - P);
      G1[A[i]].push_back(B[i]);
      G2[B[i]].push_back(A[i]);
   }
   memset(used1, false, sizeof(used1)); 
   memset(used2, false, sizeof(used2)); 

   bfs1(0);
   bfs2(N - 1);
   /*
   for (int i = 0; i < N; i++) {
      cout << i << " " << used1[i] << " " << used2[i] << endl;
   }
   */
   EDGE< int > edges;
   
   for (int i = 0; i < M; i++) {
      if (!used1[A[i]]) continue;
      if (!used1[B[i]]) continue;
      if (!used2[A[i]]) continue;
      if (!used2[B[i]]) continue;
      // cout << A[i] << " " << B[i] << " " << C[i] << endl;
      edges.emplace_back(A[i], B[i], C[i]);
   }
   
   auto res = bellman_ford(edges, N, 0);
   if (res.empty()) cout << "-1" << endl;
   else {
      assert(res[N - 1] != numeric_limits<int>::max());
      cout << max(0, -1 * res[N - 1]) << endl;
   }
   return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:113:7: error: 'assert' was not declared in this scope
  113 |       assert(res[N - 1] != numeric_limits<int>::max());
      |       ^~~~~~
a.cc:11:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   10 | #include<queue>
  +++ |+#include <cassert>
   11 |
Language: C++

#include <vector>
#include <math.h>
#include <string>
#include <ios>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

#define LL long long
using namespace std;
int main() {
	LL N,M,	P;
	cin >> N >> M >> P;
	typedef struct Edge {
		LL from;
		LL to;
		LL cost;
	};
	LL res = 0;
	vector<Edge> edge(M);
	vector<LL> min_gain(N+1);

	for (int m = 0; m < M; m++) {
		cin >> edge[m].from;
		cin >> edge[m].to;
		cin >> edge[m].cost;
		edge[m].cost = -(edge[m].cost - P);
	}
	
	for (int i = 0; i < N+1; i++) {
		min_gain[i] = INFINITY;
	}
	min_gain[0] = 0;

	for (int n = 0; n < N; n++) {
		for (int m = 0; m < M; m++) {
			if (min_gain[edge[m].to] > min_gain[edge[m].from] + edge[m].cost) {
				min_gain[edge[m].to] = min_gain[edge[m].from] + edge[m].cost;
				if (n == N - 1) {
					cout << -1;
					return 0;
				}
			}
		}
	}

	cout << max(LL(0),-min_gain[N]);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:9: warning: 'typedef' was ignored in this declaration
   17 |         typedef struct Edge {
      |         ^~~~~~~
a.cc:34:31: warning: overflow in conversion from 'float' to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} changes value from '+Inff' to '9223372036854775807' [-Woverflow]
   34 |                 min_gain[i] = INFINITY;
      |                               ^~~~~~~~
a.cc:12:12: error: expected primary-expression before 'long'
   12 | #define LL long long
      |            ^~~~
a.cc:50:21: note: in expansion of macro 'LL'
   50 |         cout << max(LL(0),-min_gain[N]);
      |                     ^~
Language: C++

#include<bits/stdc++.h>

using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
struct Edge
{
    int v,cost,nxt;
};
Edge edge[maxn];
int head[maxn];
ll dis[maxn];

int cnt;
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
    memset(edge,0,sizeof(edge));
    memset(dis,inf,sizeof(dis));
    dis[1]=0;
}
void add(int u,int v,int w)
{
    edge[cnt].v=v;
    edge[cnt].cost=w;
    edge[cnt].nxt=head[u];
    head[u]=cnt;
    cnt++;
}
int main()
{
    int n,m,p,u,v,w;
    init();
    scanf("%d%d%d",&n,&m,&p);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,-w+p);
    }
    for(int i=1;i<=n;i++)
    {
        for(int k=1;k<=n;k++)
        {
            for(int j=head[k];j!=-1;j=edge[j].nxt)
            {
                if(dis[edge[j].v]>dis[i]+edge[j].cost)
                {
                    dis[edge[j].v]=dis[i]+edge[j].cost;
                }
            }
        }
    }
    int ok=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=head[i];j!=-1;j=edge[j].nxt)
        {
            if(dis[edge[j].v]>dis[i]+edge[j].cost)
            {
                ok=1;
                break;
            }
        }
    }
    if(ok==1&&dis[n]<0)
    {
        printf("-1\n");
    }
    else if(dis[n]<0)
    {
        printf("%lld\n",-dis[n]);
    }
    else
    {
        printf("0\n");
    }
    return 0;
}


Compiler output:
a.cc:12:1: error: 'll' does not name a type
   12 | ll dis[maxn];
      | ^~
a.cc: In function 'void init()':
a.cc:20:12: error: 'dis' was not declared in this scope; did you mean 'div'?
   20 |     memset(dis,inf,sizeof(dis));
      |            ^~~
      |            div
a.cc: In function 'int main()':
a.cc:47:20: error: 'dis' was not declared in this scope; did you mean 'div'?
   47 |                 if(dis[edge[j].v]>dis[i]+edge[j].cost)
      |                    ^~~
      |                    div
a.cc:59:16: error: 'dis' was not declared in this scope; did you mean 'div'?
   59 |             if(dis[edge[j].v]>dis[i]+edge[j].cost)
      |                ^~~
      |                div
a.cc:66:15: error: 'dis' was not declared in this scope; did you mean 'div'?
   66 |     if(ok==1&&dis[n]<0)
      |               ^~~
      |               div
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const ll INF = 1e9;
struct edge{ ll from, to, cost;};

edge es[5010];
ll d[3000];
bool avail[3000];
ll N,M;

void shortest_path(ll s){
    fr(i,N)d[i] = INF;
    d[s] = 0;
    while(true){
        bool update = false;
        fr(i,M){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

bool find_negative_loop(){
    memset(d, 0, sizeof(d));

    fr(i,N){
        fr(j,M){
            edge e = es[j];
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;

                if(i == N-1) return true;
            }
        }
    }
    return false;
}


int main(){
    ll P;cin >> N >> M >> P;
    fr(i,M){
        ll a,b,c;cin >> a >> b >> c;
        es[i] = {a,b,P-c};
    }

    if(find_negative_loop()) cout << -1 << endl;
    else{
        shortest_path(1);
        cout << -d[N] << endl; 
    }
}

Compiler output:
a.cc: In function 'bool find_negative_loop()':
a.cc:66:5: error: 'memset' was not declared in this scope
   66 |     memset(d, 0, sizeof(d));
      |     ^~~~~~
a.cc:17:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   16 | #include<numeric>
  +++ |+#include <cstring>
   17 |
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const ll INF = 1e9;
struct edge{ ll from, to, cost;};

edge es[5010];
ll d[3000];
bool avail[3000];
ll N,M;

void shortest_path(ll s){
    fr(i,N)d[i] = INF;
    d[s] = 0;
    while(true){
        bool update = false;
        fr(i,M){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

bool find_negative_loop(){
    memset(d, 0, sizeof(d));

    fr(i,N){
        fr(j,M){
            edge e = es[j];
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;

                if(i == N-1) return true;
            }
        }
    }
    return false;
}

Compiler output:
a.cc: In function 'bool find_negative_loop()':
a.cc:66:5: error: 'memset' was not declared in this scope
   66 |     memset(d, 0, sizeof(d));
      |     ^~~~~~
a.cc:17:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   16 | #include<numeric>
  +++ |+#include <cstring>
   17 |
Language: C++

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class ECoinsRespawn {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    struct edge {
        int from, to, cost;

        edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost) {}

        edge() {}
    };

    int N, M, P;
    vector<edge> edges;
    vector<int> d;
    vector<bool> neg;

    void calc(int s) {
        REP(i, N) d[i] = INF;
        d[s] = 0;

        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j < edges.size(); j++) {
                auto e = edges[j];
                if (d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                }
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < edges.size(); j++) {
                auto e = edges[j];
                if (d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    neg[e.to] = true;
                }
                //if (neg[e.from]) neg[e.to] = true;
            }
        }
        if (neg[N - 1]) {
            d[N - 1] = INF;
        }
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N >> M >> P;
        edges.clear();
        d.resize(N);
        neg.resize(N);
        REP(i, M) {
            int a, b, c;
            cin >> a >> b >> c;
            edge e;
            a--;
            b--;
            c -= P;
            edges.push_back(edge(a, b, -c));
        }

        calc(0);

        if (d[N - 1] >= INF) {
            cout << -1 << endl;
        } else {
            cout << max(-d[N - 1], 0LL) << 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 <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int,int> P;

void dfs(int v, vector<vector<int>>& to, vector<bool>& f) {
  if(f[v]) return;
  f[v] = true;
  for (auto u : to[v]) {
    dfs(u,to,f);
  }
}

int main() {
  int n,m,p;
  int ans = -1;
  cin >> n >> m >> p;
  vector<vector<int>> to(n+1);
  vector<vector<int>> ot(n+1);
  vector< tuple<int,int,int> > edges;

  for (int i=0; i<m; i++) {
    int a,b,c;
    cin >> a >> b >> c;
    c = -1 * (c-p);
    to[a].push_back(b);
    ot[b].push_back(a);
    edges.emplace_back(a,b,c);
  }

  // 1 からたどり着けないやつと Nにたどり着けないやつは考慮する必要が無い
  vector<bool> from1Flag(n+1,false);
  vector<bool> toNFlag(n+1,false);
  dfs(1,to,from1Flag);
  dfs(n,ot,toNFlag);

  vector<bool> ok(n+1,false);

  for (int i=1; i<=n; i++)
    ok[i] = from1Flag[i] && toNFlag[i];

  // Bellman-Ford アルゴリズム
  vector<int> d(n+1,INT_MAX);
  d[1] = 0;
  bool updated = true;
  int step = 0;

  while(updated) {
    updated = false;
    step++;
    if(step >= n) break;

    for(int i=0; i<m; i++) {
      int a,b,c;
      tie(a,b,c) = edges[i];
      if (!ok[a]) continue;
      if (!ok[b]) continue;

      if (d[a]+c < d[b]) {
        updated = true;
        d[b] = d[a]+c;
      }
    }
  }

  if(step <e n) ans = max(0, -1 * d[n]);
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:21: error: 'INT_MAX' was not declared in this scope
   50 |   vector<int> d(n+1,INT_MAX);
      |                     ^~~~~~~
a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include <cmath>
  +++ |+#include <climits>
    8 | 
a.cc:73:12: error: 'e' was not declared in this scope
   73 |   if(step <e n) ans = max(0, -1 * d[n]);
      |            ^
a.cc:73:13: error: expected ')' before 'n'
   73 |   if(step <e n) ans = max(0, -1 * d[n]);
      |     ~       ^~
      |             )
Language: C++

#include <bits/stdc++.h>
const int MAXN=2550,MAXE=5050;
using namespace std;
int nt[MAXE],val[MAXE],to[MAXE];
int f[MAXN],d[MAXN],vis[MAXN],book[MAXN];
queue<int>q;
int num,n,m,p;
void add(int u,int v,int w){num++;nt[num]=f[u];f[u]=num;to[num]=v;val[num]=w;}

void SPFA(){
	memset(d,-0x3f,sizeof d);
	q.push(1);vis[1]=1;d[1]=0;
	while(!q.empty()){
		int u=q.front();q.pop();vis[u]=0;
		book[u]++;if(book[u]==m){flag=0;break;}
		for(int i=f[u];i;i=nt[i])
			if(d[u]+val[i]>d[to[i]]){
				d[to[i]]=d[u]+val[i];
				if(!vis[to[i]])
					q.push(to[i]),vis[to[i]]=1;
			}
	}
//	cout<<d[2]<<" "<<d[3]<<" "<<d[6]<<" ";
	if(book[n]>=n) cout<<"-1"<<endl;
	else cout<<(d[n]<0?0:d[n])<<endl;
}

int main(){
	cin>>n>>m>>p;int u,v,w;
	for(int i=1;i<=m;i++)
		cin>>u>>v>>w,add(u,v,w-p);
	SPFA();
}


Compiler output:
a.cc: In function 'void SPFA()':
a.cc:15:42: error: 'flag' was not declared in this scope
   15 |                 book[u]++;if(book[u]==m){flag=0;break;}
      |                                          ^~~~
Language: C++

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,m,p,ans=0,dis[N],head[N],nex[N],to[N],wi[N];
bool vis[N],vv[N];
ll num[N];
ll tot=1;void add(ll u,ll v,ll w){to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;}
ll spfa()
{
    memset(dis,inf,sizeof(dis));
    queue<ll>q;
    q.push(1);
    vis[1]=true;num[1]=1;
    dis[1]=0;
    while(!q.empty())
    {
        ll u=q.front();q.pop();
        vis[u]=false;
        for(ll i=head[u];i;i=nex[i])
        {
            ll v=to[i];
            if(!vv[v]) continue;
            if(dis[v]>dis[u]+wi[i])
            {
                dis[v]=dis[u]+wi[i];
                if(!vis[v])
                {
                    vis[v]=true;
                    num[v]++;
                    if(num[v]>n) return -1;
                    q.push(v);
                }
            }
        }
    }
    return max(0ll,dis[n]*-1);
}
void dfs(ll u)
{
    if(u==n) vv[u]=true;
    vis[u]=true;
    for(ll i=head[u];i;i=nex[i])
    {
        ll v=to[i];
        if(!vis[v]) dfs(v);
        if(vv[v]) vv[u]=true;
    }
}
int main()
{
    scanf("%lld%lld%lld",&n,&m,&p);
    for(ll i=1;i<=m;i++)
    {
        ll u,v,w;
        scanf("%lld%lld%lld",&u,&v,&w);
        add(u,v,w-p);
    }
    dfs(1);
    memset(vis,false,sizeof(vis));
    for(ll i=2;i<=tot;i++) wi[i]*=-1;
    printf(-1\n");
}


Compiler output:
a.cc:63:14: error: stray '\' in program
   63 |     printf(-1\n");
      |              ^
a.cc:63:16: warning: missing terminating " character
   63 |     printf(-1\n");
      |                ^
a.cc:63:16: error: missing terminating " character
   63 |     printf(-1\n");
      |                ^~~
a.cc: In function 'int main()':
a.cc:63:14: error: expected ')' before 'n'
   63 |     printf(-1\n");
      |           ~  ^~
      |              )
Language: C++

import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, m, p = na()
 
def bf(es, n, start):
    d = [999999999999] * n
    d[start] = 0
 
    for r in range(n-1):
        updated = False
        for e in es:
            if d[e[0]] == 999999999999:
                continue
            if d[e[0]] + e[2] < d[e[1]]:
                d[e[1]] = d[e[0]] + e[2]
                updated = True
        if not updated:
            break
 
    for e in es:
        if d[e[0]] < 999999999999 and d[e[0]] + e[2] < d[e[1]]:
            return None
 
    return d
 
es = []
for i in range(m):
    a, b, c = na()
    es.append((a-1, b-1, -(c-p)))
 
import collections
q = collections.deque()
q.append(n-1)
 
valid = [False] * n
valid[n-1] = True
while len(q) > 0:
    cur = q.popleft()
    for e in es:
        if e[1] == cur and not valid[e[0]]:
            valid[e[0]] = True
            q.append(e[0])
 
nes = []
for e in es:
    if valid[e[0]] and valid[e[1]]:
        nes.append(e)
es = nes
 
d = bf(es, n, 0)
if not d:
    print(-1)
else:
    print(max(0, -d[n-1]))

Compiler output:
a.cc:7:41: error: stray '#' in program
    7 | ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
      |                                         ^
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

// bellman-ford法
struct edge { int to, cost; };

void bellman_ford(int s, const vector<vector<edge>> &G, vector<ll> &d) {
    const int V = G.size();
    d = vector<ll>(V, LLINF);
    d[s] = 0;
    bool update = true;
    int i = 0;
    while (update)
    {
        update = false;
        for (int j = 0; j < V; j++)
        {
            for (edge e : G[j])
            {
                if (d[j] != -LLINF && d[j] != LLINF && d[j] + e.cost < d[e.to]) {
                    d[e.to] = d[j] + e.cost;
                    if (i == V - 1) {
                        d[e.to] = -LLINF;
                    }
                    update = true;
                }
                else if (d[j] == -LLINF && d[e.to] != -LLINF) {
                    d[e.to] = -LLINF;
                    update = true;
                }
            }
        }
        if (i < V - 1) i++;
    }
}

int main() {
    int n, m, p; cin >> n >> m >> p;
    vector<vector<edge>> G(n);
    vector<ll> dist(n);
    REP(i, m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--; c -= p;
        c *= -1;
        G[a].push_back({b,c});
    }
    bellman_ford(0, n - 1, G, dist);
    if (dist[n - 1] == -LLINF) cout << -1 << endl;
    else cout << max(0LL, -dist[n - 1]) << endl;
    getchar(); getchar();
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:23: error: invalid initialization of reference of type 'const std::vector<std::vector<edge> >&' from expression of type 'int'
   56 |     bellman_ford(0, n - 1, G, dist);
      |                     ~~^~~
a.cc:16:54: note: in passing argument 2 of 'void bellman_ford(int, const std::vector<std::vector<edge> >&, std::vector<long long int>&)'
   16 | void bellman_ford(int s, const vector<vector<edge>> &G, vector<ll> &d) {
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Language: C++

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define BELLMAN_FORD_MAX_E 10005
#define BELLMAN_FORD_MAX_V 10005

struct edge {
    int from, to, cost;
    edge(int f, int t, int c) : from(f), to(t), cost(c) {}
};

edge es[BELLMAN_FORD_MAX_E];

int d[BELLMAN_FORD_MAX_V];
bool negative[BELLMAN_FORD_MAX_V];
int V, E;

void shortest_path(int s, bool is_find_negative_loop) {
    for (int i = 0; i < V; i++)
        d[i] = (1 << 30);

    d[s] = 0;
    for (int j = 0; j < V; j++) {
        bool update = false;
        for (int i = 0; i < E; i++) {
            const edge &e = es[i];
            if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update)
            break;
    }

    if (is_find_negative_loop) {
        for (int i = 0; i < V; i++) {
            negative[i] = false;
        }

        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E; j++) {
                const edge &e = es[j];
                if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) {
                    negative[e.to] = true;
                }

                if (negative[e.from]) {
                    negative[e.to] = true;
                }
            }
        }
    }
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int p;
    cin >> V >> E >> p;
    REP(i, E) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        es[i] = edge(a, b, p - c);
    }

    shortest_path(0, true);

    if (negative[V - 1]) {
        cout << "-1" << endl;
    } else {
        cout << -d[V - 1] << endl;
    }

    return 0;
}


Compiler output:
a.cc:26:27: error: no matching function for call to 'edge::edge()'
   26 | edge es[BELLMAN_FORD_MAX_E];
      |                           ^
a.cc:23:5: note: candidate: 'edge::edge(int, int, int)'
   23 |     edge(int f, int t, int c) : from(f), to(t), cost(c) {}
      |     ^~~~
a.cc:23:5: note:   candidate expects 3 arguments, 0 provided
a.cc:21:8: note: candidate: 'constexpr edge::edge(const edge&)'
   21 | struct edge {
      |        ^~~~
a.cc:21:8: note:   candidate expects 1 argument, 0 provided
a.cc:21:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:21:8: note:   candidate expects 1 argument, 0 provided
Language: C++

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

struct edge {
    LL a;
    LL b;
    LL c;
};

int main() {
    LL N, M, P;
    cin >> N >> M >> P;
    vector<LL> d;
    d.resize(N + 1);
    fill(ALL(d), LINF);

    vector<edge> edges;
    edges.resize(M);
    REP(i, M) {
        LL a, b, c;
        cin >> a >> b >> c;
        edges[i] = {a, b, -c + P};
    }

    d[1] = 0;
    queue<LL> q;
    q.push(1);
    REP(i, N) {
        REP(j, M) {
            LL a = edges[j].a;
            LL b = edges[j].b;
            LL c = edges[j].c;
            if(!q.empty() && q.front() == a) {
                d[b] = min<LL>(d[b], d[a] + c);
                q.push(b);
            }
        }
        if(!q.empty()) {
            q.pop();
        }
    }

    LL res = d[N];
    REP(i, N) {
        REP(j, M) {
            LL a = edges[j].a;
            LL b = edges[j].b;
            LL c = edges[j].c;
            if(!q.empty() && q.front() == a) {
                d[b] = min<LL>(d[b], d[a] + c);
                q.push(b);
            }
        }
        if(!q.empty()) {
            q.pop();
        }
    }
    LL res2 = -d[N];
    if(res != res2) {
        cout << -1 << endl;
        return 0;
    }
    LL res = max<LL>(0, -d[N]);
    cout << res << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:71:8: error: redeclaration of 'long long int res'
   71 |     LL res = max<LL>(0, -d[N]);
      |        ^~~
a.cc:51:8: note: 'long long int res' previously declared here
   51 |     LL res = d[N];
      |        ^~~
Language: C++

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,p;
vector<P> G[2505];
int a[5005],b[5005],c[5005];
ll dp[2505];

int main(void){
	scanf("%d%d%d",&n,&m,&p);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		a[i]--;
		b[i]--;
		c[i]=p-c[i];
	}
	for(int i=0;i<n;i++){
		dp[i]=1LL<<60;
	}
	dp[0]=0;
	for(int i=0;i<n*3;i++){
		for(int j=0;j<m;j++){
			if(dp[a[j]]==INF)continue;
			if(dp[b[j]]>dp[a[j]]+c[j]){
				dp[b[j]]=dp[a[j]]+c[j];
				if(b[j]==(n-1) && i>=n-1){
					printf("-1\n");
					return 0;
				}
			}
		}
	}
	printf("%d\n",max(-dp[n-1],0LL));
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:38: error: 'INF' was not declared in this scope
   26 |                         if(dp[a[j]]==INF)continue;
      |                                      ^~~
Language: C++

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

struct EDGE{
    int src;
    int dst;
    int coin;
};

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n,m,p;
    cin>>n>>m>>p;
    vector<EDGE> edge(m);
    for(int i=0; i<m; i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge[i].src=a-1;
        edge[i].dst=b-1;
        edge[i].coin=-c+p;
    }
    bool cycle=false;
    int answer=INT_MAX;
    vector<vector<int>> coin(2,vector<int>(n,INT_MAX));
    int idx=0;
    coin[idx][0]=0;
    for(int i=0; i<2*n; i++){
        idx=1-idx;
        for(int j=0; j<n; j++) coin[idx][j]=INT_MAX;
        for(EDGE& e : edge){
            if(coin[1-idx][e.src]!=INT_MAX && coin[idx][e.dst]>coin[1-idx][e.src]+e.coin){
                coin[idx][e.dst]=coin[1-idx][e.src]+e.coin;
                if(e.dst==n-1){
                    if(i>=n-1 && answer>coin[idx][e.dst]) cycle=true;
                    answer=min(answer,coin[idx][e.dst]);
                }
            }
        }
    }
    if(cycle || answer=INT_MAX) cout<<-1;
    else cout<<max(0,-answer);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:14: error: lvalue required as left operand of assignment
   55 |     if(cycle || answer=INT_MAX) cout<<-1;
      |        ~~~~~~^~~~~~~~~
Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template<class T>
vector<T> Bellman_Ford(vector<Edge<T>> &edges, int V, int st) {

	const T INF = numeric_limits<T>::max();
	vector<T> dist(V, INF);
	dist[st] = 0;
	for (int i = 0; i < V - 1; i++) {
		for (const auto &ele : edges) {
			if (dist[ele.from] == INF) continue;
			dist[ele.to] = min(dist[ele.to], dist[ele.from] + ele.cost);
		}
	}

	for (int i = 0; i < V-2; i++) {
		for (const auto &ele : edges) { // finding negative loop
			if (dist[ele.from] == INF) continue;
			if (dist[ele.from] == -INF) dist[ele.to] = -INF; // src is nloop -> dst is nloop
			if (dist[ele.to] > dist[ele.from] + ele.cost) dist[ele.to] = -INF; // chmin is possible -> nloop
		}
	}

	return dist;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, P;
	cin >> N >> M >> P;

	int a, b, c;
	vector<Edge<int>> edges(M);
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--, b--;
		edges[i] = { a, b, P - c };
	}

	auto dist = Bellman_Ford(edges, N, 0);
	DMP(dist);

	int ans = -dist.back();
	if (ans == INF) cout << "-1\n";
	else if (ans < 0) cout << "0\n";
	else cout << ans << "\n";

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:20: error: 'INF' was not declared in this scope
   89 |         if (ans == INF) cout << "-1\n";
      |                    ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
long long n,m,p,a[N],b[N],c[N],d[N];
int main() {
	cin>>n>>m>>p;
	memset(d,-127,sizeof(d));
	for(int i=1; i<=m; i++)
		cin>>a[i]>>b[i]>>c[i],c[i]-=p;
	d[1]=0;
	for(int i=1; i<n; i++)
		for(int j=1; j<=m; j++)
			d[b[j]]=max(d[b[j]],d[a[j]]+c[j]);
	long ans=d[n-1];
	for(int i=1; i<n; i++)
		for(int j=1; j<=m; j++)
			d[b[j]]=max(d[b[j]],d[a[j]]+c[j]);
	cout<<(ans<d[n-1]?-1:max(ans,1ll*0));
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:33: error: no matching function for call to 'max(long int&, long long int)'
   18 |         cout<<(ans<d[n-1]?-1:max(ans,1ll*0));
      |                              ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:18:33: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   18 |         cout<<(ans<d[n-1]?-1:max(ans,1ll*0));
      |                              ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:18:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   18 |         cout<<(ans<d[n-1]?-1:max(ans,1ll*0));
      |                              ~~~^~~~~~~~~~~
Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template<class T>
vector<T> Bellman_Ford(vector<Edge<T>> &edges, int V, int st) {
	
	const T INF = numeric_limits<lint>::max();
	vector<T> dist(V, INF);
	dist[st] = 0;
	for (int i = 0; i <= 2 * V; i++) {
		for (const auto &ele : edges) {
			if (dist[ele.from] == INF) continue;
			if (dist[ele.to] > dist[ele.from] + ele.cost) {
				dist[ele.to] = dist[ele.from] + ele.cost;
				if (ele.to == V - 1 && i >= V) return vector<T>(1);
			}
		}
	}a

	return dist;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, P;
	cin >> N >> M >> P;

	int a, b, c;
	vector<Edge<lint>> edges(M);
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--, b--;
		edges[i] = { a, b, P - c };
	}

	auto dist = Bellman_Ford(edges, N, 0);
	DMP(dist);

	lint ans = -dist.back();
	if (dist.size() == 1) cout << "-1\n";
	else if (ans < 0) cout << "0\n";
	else cout << ans << "\n";

	return 0;
}

Compiler output:
a.cc: In function 'std::vector<_Tp> Bellman_Ford(std::vector<Edge<T> >&, int, int)':
a.cc:59:10: error: 'a' was not declared in this scope
   59 |         }a
      |          ^
a.cc: In function 'std::vector<_Tp> Bellman_Ford(std::vector<Edge<T> >&, int, int) [with T = long long int]':
a.cc:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
Language: C++

#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M, P;
vector<vector<pair<ll, int>>> graph;
vector<ll> dist;

bool spfa(int s) {
    dist.assign(N, LINF);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    vector<bool> in_queue(N);
    vector<int> cnt_update(N, 0);
    cnt_update[s]++;

    while (!que.empty()) {
        int v = que.front(); que.pop();
        in_queue[v] = false;
        if (v == N - 1 && cnt_update[v] == N) {
            return true;
        }

        for (auto& e : graph[v]) {
            if (dist[v] + e.first < dist[e.second]) {
                dist[e.second] = dist[v] + e.first;

                if (!in_queue[e.second]) {
                    que.push(e.second);
                    in_queue[e.second] = true;

                    cnt_update[e.second]++;
                    if (cnt_update[e.second] == N && e.second == N - 1) {
                        return true;
                    }
                    if (cnt_update[e.second] == 2 * N) return false;
                }
            }
        }
    }

    return false;
}

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 <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

struct BellmanFord{
	struct Edge{
		int  from,to; ll cost;
		Edge(){}
		Edge(int from,int to,ll cost):from(from),to(to),cost(cost){}
	};

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

	vector<Edge> es;
	void add_edge(int from,int to,ll cost){
		es.push_back(Edge(from,to,cost));
		G[from].push_back(to);
	}

	void dfs(int v){
		if(used[v])return ;
		used[v]=1;
		for(int u:G[v]){
			dfs(u);
		}
	}
	ll build(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];
		}
		vector<ll> ds(n,1e18);
		ds[from]=0;
		for(int i=0;i<n;i++){
			bool update=0;
			for(auto e:es){
				if(!reach[e.from]||!reach[e.to]||ds[e.from]==1e18) continue;
				if(ds[e.to]>ds[e.from]+e.cost){
					ds[e.to]=ds[e.from]+e.cost;
					update=1;
				}
			}
			if(!update)break;
			if(i==n-1){
				neg_loop=1;
				return 1e18;
			}
		}
		neg_loop=0;
		return ds[to];
	}
};

int 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.build(0,n-1,neg_loop);
	if(neg_loop){
		cout << -1 << endl;
		return 0;
	}
	else{
		cout << max((ll)0,(ll)-res) << endl;
		return 0;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:9: error: 'BellmanFord' is not a template
   63 |         BellmanFord<int> G(n);
      |         ^~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs
struct edge {
	int to, cost;
};

class dijkstra {
  private:
	int V;
	vector<int> d;
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		d.resize(v + 1);
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d.begin(), d.end(), 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)
				continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}
	vector<int> get_d() {
		return d;
	}

	int find(int e) {
		return d[e];
	}
};
vector<int> mod_pow(int n, int m, int mod) {
	vector<int> ret(m);
	ret[0] = 1;
	REP(i, 1, m + 1) {
		ret[i] = (ret[i - 1] * n) % mod;
	}
	return ret;
}
vector<edge> vec[2512], unvec[2512];
vector<int> ifGoal;
int memo[2501];
int mx = 100000000000ll;
int dfs(int now, int n, int p) {
	int ret = 0;
	if (now == n) {
		ret = memo[n];
	}
	rep(i, vec[now].size()) {
		edge it = vec[now][i];
        if(memo[now]<=-2)memo+=2;
		if (memo[it.to] == 0) {
			memo[it.to] = memo[now] + it.cost - p;
			if (memo[it.to] <= 0)
				memo[it.to] -= 2;
            if(memo[now]<=0)memo-=2;
			int cnt = dfs(it.to, n, p);
			if (cnt == -1)
				return -1;
			else
				ret = max(ret, cnt);
		}
		else if (ifGoal[it.to] != mx && memo[it.to] < (memo[now] + it.cost - p)) {
			return -1;
		}
	}
	memo[now] = 0;
	return ret;
}
signed main(int argc, char* argv[]) {
	int n, m, p;
	cin >> n >> m >> p;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		vec[a].push_back({b, c});
		unvec[b].push_back({a, c});
	}
	dijkstra d(n, n, unvec);
	ifGoal = d.get_d();
	memo[1] = 1;
	int a = dfs(1, n, p);
    if(a<=-2)cout<<0<<endl;
	else if (a == -1||a==0)
		cout << a << endl;
	else
		cout << a - 1 << endl;
}


Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int, long long int)':
a.cc:76:30: error: incompatible types in assignment of 'int' to 'long long int [2501]'
   76 |         if(memo[now]<=-2)memo+=2;
      |                          ~~~~^~~
a.cc:81:33: error: incompatible types in assignment of 'int' to 'long long int [2501]'
   81 |             if(memo[now]<=0)memo-=2;
      |                             ~~~~^~~
a.cc: At global scope:
a.cc:95:8: warning: first argument of 'int main(long long int, char**)' should be 'int' [-Wmain]
   95 | signed main(int argc, char* argv[]) {
      |        ^~~~
Language: C++

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int sz=5005;
long long d[sz];
int n,m,p;
int f[sz],t[sz],w[sz];
long long inf=1e18,ans;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d %d %d",&n,&m,&p);
   for(int i=0;i<m;i++){
        scanf("%d %d %d",&f[i],&t[i],&w[i]);
        w[i]=p-w[i];
    }
    for(int i=1;i<=n;i++) d[i]=inf;
    bool flag=0;
    d[1]=0;
    for(int i=0;i<10*n;i++){
        for(int j=0;j<m;j++){
            int u=f[j];
            int v=t[j];
            int k=w[j];
            if(d[u]>=inf) continue;
            if(d[v]>d[u]+k){
                if((v==n&&i>=n) flag=1;
                d[v]=max(d[u]+k,-inf);
            }
        }
        if(flag){
            cout<<-1;
            return 0;
        }
    }
    if(d[n]==inf) cout<<-1;
    else{
        d[n]=-d[n];
        ans=max(ans,d[n]);
        cout<<ans;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:32: error: expected ';' before 'flag'
   30 |                 if((v==n&&i>=n) flag=1;
      |                                ^~~~~
      |                                ;
a.cc:31:38: error: expected ')' before ';' token
   31 |                 d[v]=max(d[u]+k,-inf);
      |                                      ^
      |                                      )
a.cc:30:19: note: to match this '('
   30 |                 if((v==n&&i>=n) flag=1;
      |                   ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)


// from: https://atcoder.jp/contests/abc137/submissions/6831647
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,Ginv;
	vector<int> reach;
	BellmanFord(int n):n(n),G(n),reach(n,0){}

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

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

	T build(int from,int to,int &neg_loop){
		fill(reach.begin(),reach.end(),0);
		dfs(i);
		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[to];
	}
};

ll n,m,p,ans;

int main(){
	cin>>n>>m>>p;
	BellmanFord<ll> f(n);
	rep(i,m){
		ll a,b,x;
		cin>>a>>b>>x;
		f.add_edge(a-1,b-1,p-x);
	}
	int neg_loop;
	ans = f.build(0,n-1,neg_loop);
	cout<<(neg_loop?-1:max(-ans,0LL))<<endl;
	return 0;
}

Compiler output:
a.cc: In member function 'T BellmanFord<T>::build(int, int, int&)':
a.cc:40:21: error: 'i' was not declared in this scope
   40 |                 dfs(i);
      |                     ^
Language: C++

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
struct edge { int to, from, cost; };
int INF = 1000000;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, p;
  cin >> n >> m >> p;
 
  int a[m], b[m], c[m];
  for(int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
 
  edge es[m];
  for(int i = 0; i < m; i++) {
    es[i] = (edge) { b[i], a[i], p - c[i]};
  }
  int d[n];
  for(int i = 0; i < n; i++) d[i] = INF;
  d[0] = 0;
 
  bool neg_loop = false;
  for(int i = 0; i < 2 * n; i++) {
    for(int j = 0; j < m; j++) {
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        if(i >= n && e.to == n - 1) {
          neg_loop = true;
          break;
        }
      }
 
    }
  }
 
  if(neg_loop) {
    cout << -1 << "\n";
    return 0;
  }
 
 
  cout << max(0LL, -d[n - 1]) << "\n";
  return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'