Problem p03722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using P = pair<ll, ll>;

#define FOR(k, m, n) for (ll(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define WAITING(str)                                                           \
  int str;                                                                     \
  std::cin >> str;
#define DEBUGING(str) cout << #str << " " str << endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007; // 10^9+7

struct Edge {
  ll from, to, cost;
};

ll N, M;
vector<Edge> edges;
vector<ll> d;
ll score = INFL;

using namespace chrono;
bool shortest_path(ll s) {
  auto start = system_clock::now();
  fill(d.begin(), d.end(), INFL);
  d[s] = 0;
  while (true) {
    bool update = false;
    for (const auto &e : edges) {
      if (d[e.from] != INFL && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      return true;

    auto end = system_clock::now();
    auto mill = duration_cast<milliseconds>(end - start).count();
    if (mill > 1500 && score == INFL)
      score = d.back();
    if (mill > 1800 && score != d.back())
      return false;
  }
}

int main() {
  cin >> N >> M;
  edges.resize(N);
  d.resize(N);

  REP(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c = -c;
    edges.push_back({a, b, c});
  }
  if (!shortest_path(0)) {
    cout << "inf" << endl;
  } else {
    cout << -d.back() << endl;
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using P = pair<ll, ll>;

#define FOR(k, m, n) for (ll(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define WAITING(str)                                                           \
  int str;                                                                     \
  std::cin >> str;
#define DEBUGING(str) cout << #str << " " str << endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007; // 10^9+7

struct Edge {
  ll from, to, cost;
};

ll N, M;
vector<Edge> edges;
vector<ll> d;
ll score = INFL;

using namespace chrono;
bool shortest_path(ll s) {
  auto start = system_clock::now();
  fill(d.begin(), d.end(), INFL);
  d[s] = 0;
  while (true) {
    bool update = false;
    for (const auto &e : edges) {
      if (d[e.from] != INFL && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      return true;

    auto end = system_clock::now();
    auto mill = duration_cast<milliseconds>(end - start).count();
    if (mill > 1500 && score == INFL)
      score = d.back();
    if (mill > 1800) {
      return score == d.back();
    }
  }
}

int main() {
  cin >> N >> M;
  edges.resize(N);
  d.resize(N);

  REP(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c = -c;
    edges.push_back({a, b, c});
  }
  if (!shortest_path(0)) {
    cout << "inf" << endl;
  } else {
    cout << -d.back() << endl;
  }

  return 0;
}