Language: C++

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

struct edge {
    long long to, cost;
};
// firstがその頂点までの最短距離, secondは頂点番号
typedef pair<long long, long long> P;

void dijkstra(long long s, vector<vector<edge>>& G, vector<long long>& d) {//始点、隣接リスト、距離を渡す
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        for (long long i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long INF = 1000000000000007;
    
    long long n,m,p;
    cin >> n >> m >> p;
    vector<vector<edge>> forwardG(n);
    vector<long long> forwardD(n, INF);
    vector<vector<edge>> backG(n);
    vector<long long> backD(n, INF);
    long long a, b, c;
    for (long long i = 0; i < M; i++) {
        cin >> a >> b >> c;
        a--;b--;
        forwardG[a].push_back({b, p-c});
        backG[a].push_back({b,p-c});
    }
    dijkstra(0, forwardG, forwardD);
    dijkstra(n-1, backG, backD);
    long long ans=0;
    if(backD[0]==INF){
      ans -= forwardD[n-1];
      ans = max(ans,0);
    }else{
      if(forwardD[n-1]+backD[0]>=0){
        ans -= forwardD[n-1];
        ans = max(ans,0);
      }else{
        ans = -1;
      }
    }
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:31: error: 'M' was not declared in this scope
   43 |     for (long long i = 0; i < M; i++) {
      |                               ^
a.cc:54:16: error: no matching function for call to 'max(long long int&, int)'
   54 |       ans = max(ans,0);
      |             ~~~^~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:54:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   54 |       ans = max(ans,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
a.cc:58:18: error: no matching function for call to 'max(long long int&, int)'
   58 |         ans = max(ans,0);
      |               ~~~^~~~~~~
/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:58:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   58 |         ans = max(ans,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