Problem p03722 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);

struct Edge {
  int to;
  LL cost;
  Edge(int t, LL c = 0) : to(t), cost(c) {}
  bool operator>(const Edge &rhs) const { return cost > rhs.cost; }
  bool operator<(const Edge &rhs) const { return cost < rhs.cost; }
};
using Graph = vector<vector<Edge>>;

bool BellmanFord(const Graph &G, vector<LL> &d, int s) {
  const int V = G.size();
  for (int i = 0; i < V; ++i)
    d[i] = LINF;
  d[s] = 0;

  for (int lp = 0; lp <= V; ++lp) {
    for (int i = 0; i < V; ++i) {
      for (const auto &e : G[i]) {
        if (d[i] != LINF && d[e.to] > d[i] + e.cost) {
          d[e.to] = d[i] + e.cost;
          if (lp == V && e.to == V - 1)
            return true;
        }
      }
    }
  }
  return false;
}

int main() {
  // 1->Nのパスに有向閉路があるか？
  int N, M;
  cin >> N >> M;
  Graph G(N);
  FOR(i, 0, N) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].emplace_back(b, -c);
  }
  VL dist(N, 0);
  bool include_N_loop = BellmanFord(G, dist, 0);
  if (include_N_loop)
    cout << "inf\n";
  else
    cout << -dist.back() << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);

struct Edge {
  int to;
  LL cost;
  Edge(int t, LL c = 0) : to(t), cost(c) {}
  bool operator>(const Edge &rhs) const { return cost > rhs.cost; }
  bool operator<(const Edge &rhs) const { return cost < rhs.cost; }
};
using Graph = vector<vector<Edge>>;

bool BellmanFord(const Graph &G, vector<LL> &d, int s) {
  const int V = G.size();
  for (int i = 0; i < V; ++i)
    d[i] = LINF;
  d[s] = 0;

  for (int lp = 0; lp <= V; ++lp) {
    for (int i = 0; i < V; ++i) {
      for (const auto &e : G[i]) {
        if (d[i] != LINF && d[e.to] > d[i] + e.cost) {
          d[e.to] = d[i] + e.cost;
          if (lp == V && e.to == V - 1)
            return true;
        }
      }
    }
  }
  return false;
}

int main() {
  // 1->Nのパスに有向閉路があるか？
  int N, M;
  cin >> N >> M;
  Graph G(N);
  FOR(i, 0, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].emplace_back(b, -c);
  }
  VL dist(N, 0);
  bool include_N_loop = BellmanFord(G, dist, 0);
  if (include_N_loop)
    cout << "inf\n";
  else
    cout << -dist.back() << "\n";
}