Problem p02868 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
  do {                                                                         \
  } while (0)
#define dump(x)                                                                \
  do {                                                                         \
  } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

constexpr LL INF = 1LL << 60;

template <typename T = pair<int, LL>>
void Dijkstra(int s, vector<vector<edge>> &g, vector<LL> &d) {
  int numv = d.size();
  priority_queue<T, vector<T>, greater<T>> q;
  for (int i = 0; i < numv; ++i)
    d[i] = INF;
  d[s] = 0;
  q.emplace(0, s);

  while (!q.empty()) {
    T p = q.top();
    q.pop();
    LL v = p.second; // vertex
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); ++i) {
      edge &e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.emplace(d[e.to], e.to);
      }
    }
  }
}

void solve() {
  int n, m, l, r, c;
  cin >> n >> m;
  vector<vector<edge>> es(n);
  REP(i, 0, m) {
    cin >> l >> r >> c;
    --l;
    --r;
    es[l].pb(r, c);
  }
  REP(i, 1, n) es[i].pb(i - 1, 0);
  VLL d(n);
  Dijkstra(0, es, d);
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
}

int main() {
  solve();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
  do {                                                                         \
  } while (0)
#define dump(x)                                                                \
  do {                                                                         \
  } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

constexpr LL INF = 1LL << 60;

template <typename T = pair<LL, int>>
void Dijkstra(int s, vector<vector<edge>> &g, vector<LL> &d) {
  int numv = d.size();
  priority_queue<T, vector<T>, greater<T>> q;
  for (int i = 0; i < numv; ++i)
    d[i] = INF;
  d[s] = 0;
  q.emplace(0, s);

  while (!q.empty()) {
    T p = q.top();
    q.pop();
    LL v = p.second; // vertex
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); ++i) {
      edge &e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.emplace(d[e.to], e.to);
      }
    }
  }
}

void solve() {
  int n, m, l, r, c;
  cin >> n >> m;
  vector<vector<edge>> es(n);
  REP(i, 0, m) {
    cin >> l >> r >> c;
    --l;
    --r;
    es[l].pb(r, c);
  }
  REP(i, 1, n) es[i].pb(i - 1, 0);
  VLL d(n);
  Dijkstra(0, es, d);
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
}

int main() {
  solve();

  return 0;
}