Language: C++

#include<iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REPbit(bit, n)  for(int bit = 0; bit < (int)(1<<n); ++bit)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = (ll) 1e9 + 7;
const int MAX_INT = 1 << 17;

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}

template<class T>
class SegTree {
    int n;
    vector<T> data;
    T def;
    function<T(T, T)> operation;
    function<T(T, T)> update;

    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b)
            return data[k];
        else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
            return operation(c1, c2);
        }
    }

public:
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
            function<T(T, T)> _update)
            : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i) {
        return data[i + n - 1];
    }
};

struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

struct ListNode {
    int val;
    ListNode *next;

    ListNode(int x) : val(x), next(NULL) {}
};

const ll MAX_E = 10010;
const ll MAX_V = 2010;
ll V,E;
struct edge {
    ll from, to, cost;
};
edge ES[MAX_E];
ll d[MAX_V];

void Bellman_short(int s) {
    REP(i, V+1)d[i] = LLONG_MAX;
    d[s] = 0;
    while (true) {
        bool up = false;
        REP(i, E) {
            edge e = ES[i];
            if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                up = true;
            }
        }
        if (!up)break;
    }
}

bool Bellman_negLoop() {
    memset(d, 0, sizeof(d));
    REP(i, V)
        REP(j, E) {
            edge e = ES[j];
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == V - 1)return true;
            }

        }
    return false;
}


int main() {
    cin >> V >> E;
    REP(i, E) {
        ll a, b, c;
        cin >> a >> b >> c;
        ES[i] = edge{a, b, -c};
    }
    if (Bellman_negLoop()) {
        PRI("inf")
        return 0;
    }
    Bellman_short(1);
    PRI(-d[V])
    return 0;
}

Compiler output:
a.cc: In function 'void Bellman_short(int)':
a.cc:157:23: error: 'LLONG_MAX' was not declared in this scope
  157 |     REP(i, V+1)d[i] = LLONG_MAX;
      |                       ^~~~~~~~~
a.cc:15:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   14 | #include <functional>
  +++ |+#include <climits>
   15 | 
a.cc:163:30: error: 'LLONG_MAX' was not declared in this scope
  163 |             if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) {
      |                              ^~~~~~~~~
a.cc:163:30: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'