Language: C++

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

const int NMAX = 1000;
const int MMAX = 2000;
int a[MMAX], b[MMAX];
ll c[MMAX];
ll dist[NMAX];
const ll INF = 1LL << 50;

int main(){
    int n,m;
    cin >> n>> m;
    rep(i,m){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        c[i]*=-1;
    }
    rep(i,n)dist[i]=INF;
    dist[0] = 0;
    // this upper loop is to make while loop
    rep(loop,n-1){
        // this loop actually check all given data
        rep(i,m){
            // this means, so far, any data arrived to this ball
            if(dist[a[i]]==INF)continue;
            
            if(dist[b[i]] > dist[a[i]]+c[i]){
                dist[b[i]] =dist[a[i]]+c[i];
            }
        }
    }
    ll ans = dist[n-1];

    // check whether close or not
    /*
        if closed, loops decrease the value of ans.
        So how to decide the number of loops required?
        The link bellow articulate it and it says,
        1 loop with updating the value to -inf;
        http://sigma1113.hatenablog.com/entry/2019/08/12/130042
    */
    bool neg[NMAX];
    rep(i,n)neg[i]=false;
    rep(loop,n){
        // this loop actually check all given data
        rep(i,m){
            // this means, so far, any data arrived to this ball
            if(dist[a[i]]==INF)continue;
            
            if(dist[b[i]] > dist[a[i]]+c[i]){
                dist[b[i]] = dist[a[i]]+c[i];
                neg[b[i]] = true;
            }
            if(neg[a[i]])neg[b[i]]=true;
        }
    }
    if(neg[n-1])cout<<"inf"<<endl;
    else cout << -ans << endl;
    return 0;
}


// int n,m;
// int const MAX_N = 1000;
// struct edge{ll from,to,cost; };
// vector<edge> G[MAX_N];
// // vector<edge> G;
// ll d[MAX_N];

// void bfs(){
//     queue<edge> q;
//     q.push(edge{0,0,0});
//     while(!q.empty()){
//         edge st = q.front() ;q.pop();
//         bool update = false;
//         // check st's to prop
//         for(int i=0;i<G[st.from].size();i++){
//             edge ds = G[st.from][i];
//             // printf("from:%d, to:%d, d:%d\n",st.to,ds.to,d[st.to]+ds.cost);
//             // printf("%d, %d\n",d[st.to],ds.cost);
//             if(d[st.to]+ds.cost < d[ds.to]){
//                 printf("from:%d, to:%d, d:%d\n",i,ds.to,d[st.to]+ds.cost);
//                 d[ds.to] = d[st.to]+ds.cost;
//                 printf("%d, %d\n",d[st.to],ds.cost);
//                 update = true;
//                 q.push(ds);
//             }
//         }
//         if(!update){
//             break;
//         }
//     }
// }

// int main(){
//     // init
//     cin >> n >> m;
//     rep(i,m){
//         ll a,b,c;
//         cin >> a >> b >> c;
//         a--;b--;
//         G[a].push_back(edge{a,b,-1*c});
//         // G.push_back(edge{a,b,-1*c});
//     }
//     rep(i,m)d[i]=INF;
//     d[0] = 0;
//     bfs();
//     cout << d[n-1]<<endl;
//     return 0;
// }

Compiler output:
a.cc:79:10: error: redefinition of 'const ll INF'
   79 | const ll INF = 1LL << 50;
      |          ^~~
a.cc:8:10: note: 'const ll INF' previously defined here
    8 | const ll INF = +10010010000;
      |          ^~~