Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <vector>
using namespace std;
const long long INF = 0x3f3f3f3f;
typedef long long ll;
long long dis[2555]={0};
struct node{
    long long dis;
    int pos;
    bool operator<(const node &t)const{
        return dis>t.dis;
    }
};
vector<node>edg[2555];
bool vis[2555]={0};
int inq[2555]={0};
bool SPFA(int n)
{
    memset(vis,false,sizeof(vis));
    memset(inq,0,sizeof(inq));
    queue<int> Q;
    for(int i = 2;i <= n;i++) dis[i] = INF;
    vis[1] = true;
    inq[1] = 1;
    Q.push(1);
    int t,j;
    while(!Q.empty())
    {
        int cur = Q.front();
        Q.pop();
        vis[cur] = false;
        for(int i=0;i<edg[t].size();i++)
        {
            j=edg[t][i].pos;
            if(dis[t]+edg[t][i].dis<dis[j]){
                dis[j]=dis[t]+edg[t][i].dis;
                if(!visit[j]){
                    inq[j]++;
                    if(inq[j]>=n)
                        return false;
                    Q.push(j);
                    visit[j]=1;
                }
            }
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m,k;
    int a,b;
    long long num;
    cin >> n >> m >> k;
    for(int i=0;i<m;i++){
        cin >> a >> b >> num;
        edg[a].push_back({k-num,b});
    }
    for(int i=1;i<=n;i++)
        sort(edg[i].begin(),edg[i].end());
    if(spfa(n)){
        int maxn=0;
        for(int i=1;i<=n;i++)
        maxn=min(maxn,dis[i]);
        cout << 0ll-maxn <<endl;
    }
    else
        cout << -1 <<endl;

    return 0;
}


Compiler output:
a.cc: In function 'bool SPFA(int)':
a.cc:44:21: error: 'visit' was not declared in this scope
   44 |                 if(!visit[j]){
      |                     ^~~~~
a.cc:9:1: note: 'std::visit' is defined in header '<variant>'; this is probably fixable by adding '#include <variant>'
    8 | #include <stack>
  +++ |+#include <variant>
    9 | #include <vector>
a.cc: In function 'int main()':
a.cc:69:8: error: 'spfa' was not declared in this scope
   69 |     if(spfa(n)){
      |        ^~~~
a.cc:72:17: error: no matching function for call to 'min(int&, long long int&)'
   72 |         maxn=min(maxn,dis[i]);
      |              ~~~^~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:72:17: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   72 |         maxn=min(maxn,dis[i]);
      |              ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:72:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   72 |         maxn=min(maxn,dis[i]);
      |              ~~~^~~~~~~~~~~~~