Language: C++

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

using namespace std;
typedef long long ll;
typedef pair<int, ll> pa;

struct edge {
    int to;
    ll coin;
};

int n;
ll p;
vector<vector<edge>> graph;
vector<vector<int>> b_graph;
vector<bool> reachable;
bool is_inf;

void backdfs(int now) {
    reachable[now] = true;
    for (auto to:b_graph[now]) {
        if (reachable[to])continue;

        backdfs(to);
    }
}

ll bfs() {
    queue<pa> vertex;
    vertex.push(pa(0, 0));
    vertex.push(pa(-1, 0));
    int depth = 0;
    vector<ll> maxpoint(n, -3643641919810114514);

    while (true) {
        pa now_edge = vertex.front();
        int nowv = now_edge.first;
        vertex.pop();
        if (nowv == -1) {
            if (vertex.empty()) break;
            depth++;
            vertex.push(pa(-1, -1));
        } else {
            if (maxpoint[nowv] <= now_edge.second) {
                maxpoint[nowv] = now_edge.second;
                if (nowv == n - 1 && depth > 10000) {
                    is_inf = true;
                    cout << -1 << endl;
                    return -1;
                }
                for (auto next:graph[nowv]) {
                    ll point = now_edge.second + next.coin - p;
                    if (point > maxpoint[next.to] && reachable[next.to]) {
                        maxpoint[next.to] = point;
                        vertex.push(pa(next.to, point));
                    }
                }
            }
        }
    }

    return max(0, maxpoint[n - 1]);
}

int main() {
    int m;
    cin >> n >> m >> p;
    graph = vector<vector<edge>>(n);
    b_graph = vector<vector<int>>(n);

    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(edge{b, c});
        b_graph[b].push_back(a);
    }

    reachable = vector<bool>(n);
    backdfs(n - 1);

    ll ret = bfs();
    if (!is_inf)cout << ret << endl;
    return 0;
}

Compiler output:
a.cc: In function 'll bfs()':
a.cc:65:15: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   65 |     return max(0, maxpoint[n - 1]);
      |            ~~~^~~~~~~~~~~~~~~~~~~~
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:65:15: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   65 |     return max(0, maxpoint[n - 1]);
      |            ~~~^~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:4:
/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:65:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   65 |     return max(0, maxpoint[n - 1]);
      |            ~~~^~~~~~~~~~~~~~~~~~~~