Problem p03722 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
const ll E = 1e18 + 7;
#define F first
#define S second
#define MK make_pair
const ll MOD = 1000000007;

vector<vector<ll>> to(10000), from(10000);

bool table[10000] = {}, fable[10000] = {};

void tdfs(ll a) {
  table[a] = true;
  for (int i = 0; i < to[a].size(); i++) {
    if (!table[to[a][i]]) {
      tdfs(to[a][i]);
    }
  }
}

void fdfs(ll a) {
  fable[a] = true;
  for (int i = 0; i < from[a].size(); i++) {
    if (!fable[from[a][i]]) {
      fdfs(from[a][i]);
    }
  }
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> e;
  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    to[a].push_back(b);
    from[b].push_back(a);
    e.push_back({a, b, -1 * c});
  }
  vector<ll> v(n, E);
  v[0] = 0;
  for (int i = 0; i < n + 10; i++) {
    for (int t = 0; t < e.size(); t++) {
      vector<ll> E = e[t];
      v[E[1]] = min(v[E[1]], v[E[0]] + E[2]);
    }
  }
  tdfs(0);
  fdfs(n - 1);
  bool inf = false;
  for (int i = 0; i < n + 100; i++) {
    for (int t = 0; t < e.size(); t++) {
      vector<ll> E = e[t];
      if (v[E[1]] > v[E[0]] + E[2] && table[E[1]] && fable[E[1]]) {
        inf = true;
      }
      v[E[1]] = min(v[E[1]], v[E[0]] + E[2]);
    }
  }
  if (inf) {
    cout << "inf" << endl;
  } else {
    cout << -1 * v[n - 1] << endl;
    assert(false);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
const ll E = 1e18 + 7;
#define F first
#define S second
#define MK make_pair
const ll MOD = 1000000007;

vector<vector<ll>> to(10000), from(10000);

bool table[10000] = {}, fable[10000] = {};

void tdfs(ll a) {
  table[a] = true;
  for (int i = 0; i < to[a].size(); i++) {
    if (!table[to[a][i]]) {
      tdfs(to[a][i]);
    }
  }
}

void fdfs(ll a) {
  fable[a] = true;
  for (int i = 0; i < from[a].size(); i++) {
    if (!fable[from[a][i]]) {
      fdfs(from[a][i]);
    }
  }
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> e;
  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    to[a].push_back(b);
    from[b].push_back(a);
    e.push_back({a, b, -1 * c});
  }
  vector<ll> v(n, E);
  v[0] = 0;
  for (int i = 0; i < n + 10; i++) {
    for (int t = 0; t < e.size(); t++) {
      vector<ll> E = e[t];
      v[E[1]] = min(v[E[1]], v[E[0]] + E[2]);
    }
  }
  tdfs(0);
  fdfs(n - 1);
  bool inf = false;
  for (int i = 0; i < n + 100; i++) {
    for (int t = 0; t < e.size(); t++) {
      vector<ll> E = e[t];
      if (v[E[1]] > v[E[0]] + E[2] && table[E[1]] && fable[E[1]]) {
        inf = true;
      }
      v[E[1]] = min(v[E[1]], v[E[0]] + E[2]);
    }
  }
  if (inf) {
    cout << "inf" << endl;
  } else {
    cout << -1 * v[n - 1] << endl;
  }

  return 0;
}