Problem p02362 (C++)

Buggy submission (status: Runtime Error):
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class DirectedGraph {
  struct edge {
    int from;
    int to;
    int cost;
  };

  int edge_num = 0;

public:
  int V;
  int E;
  vector<edge> edges;

  DirectedGraph(int v, int e) : V(v), edges(e), E(e){};

  void add_edge(int from, int to, int cost) {
    edges[edge_num++] = {from, to, cost};
  }

  // O(E * V)
  vector<int> bellman_ford(int s) {
    vector<int> d(V, INF);
    d[s] = 0;

    for (int j = 0; j < V; j++) {
      bool update = false;
      for (int i = 0; i < E; i++) {
        edge e = edges[i];
        if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;

          if (j == V - 1) {
            vector<int> dd(0);
            return dd;
          }
        }
      }

      if (!update)
        break;
    }

    return move(d);
  }
};

signed main() {
  int V, E, start;
  cin >> V >> E >> start;

  DirectedGraph dg = DirectedGraph(V, E);

  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    dg.add_edge(s, t, d);
  }

  vector<int> dis = dg.bellman_ford(start);

  if (dis.size() == 0) {
    cout << "NEGATIVE CYCLE" << endl;
  }

  for (int i = 0; i < V; i++) {
    if (dis[i] == INF) {
      cout << "INF" << endl;
      continue;
    }

    cout << dis[i] << endl;
  }

  return 0;
}


Fixed submission:
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class DirectedGraph {
  struct edge {
    int from;
    int to;
    int cost;
  };

  int edge_num = 0;

public:
  int V;
  int E;
  vector<edge> edges;

  DirectedGraph(int v, int e) : V(v), edges(e), E(e){};

  void add_edge(int from, int to, int cost) {
    edges[edge_num++] = {from, to, cost};
  }

  // O(E * V)
  vector<int> bellman_ford(int s) {
    vector<int> d(V, INF);
    d[s] = 0;

    for (int j = 0; j < V; j++) {
      bool update = false;
      for (int i = 0; i < E; i++) {
        edge e = edges[i];
        if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;

          if (j == V - 1) {
            vector<int> dd(0);
            return dd;
          }
        }
      }

      if (!update)
        break;
    }

    return move(d);
  }
};

signed main() {
  int V, E, start;
  cin >> V >> E >> start;

  DirectedGraph dg = DirectedGraph(V, E);

  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    dg.add_edge(s, t, d);
  }

  vector<int> dis = dg.bellman_ford(start);

  if (dis.size() == 0) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for (int i = 0; i < V; i++) {
    if (dis[i] == INF) {
      cout << "INF" << endl;
      continue;
    }

    cout << dis[i] << endl;
  }

  return 0;
}