Problem p02868 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef pair<ll, ll> P;

vector<P> G[100100];

vector<ll> d(100100, INF);

void dijkstra() {
  d[0] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push({0, 0});
  while (!pq.empty()) {
    ll dist = pq.top().first, v = pq.top().second;
    pq.pop();
    if (d[v] < dist)
      continue;
    for (auto e : G[v]) {
      ll c = e.first, u = e.second;
      if (chmin(d[u], d[v] + c)) {
        pq.push(e);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, m;
  cin >> n >> m;
  rep(i, n - 1) G[i + 1].push_back({0, i});
  rep(i, m) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].push_back({c, r});
  }

  dijkstra();
  cout << (d[n - 1] == INF ? -1 : d[n - 1]) << '\n';

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef pair<ll, ll> P;

vector<P> G[100100];

vector<ll> d(100100, INF);

void dijkstra() {
  d[0] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push({0, 0});
  while (!pq.empty()) {
    ll dist = pq.top().first, v = pq.top().second;
    pq.pop();
    if (d[v] < dist)
      continue;
    for (auto e : G[v]) {
      ll c = e.first, u = e.second;
      if (chmin(d[u], d[v] + c)) {
        pq.push({d[u], u});
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, m;
  cin >> n >> m;
  rep(i, n - 1) G[i + 1].push_back({0, i});
  rep(i, m) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].push_back({c, r});
  }

  dijkstra();
  cout << (d[n - 1] == INF ? -1 : d[n - 1]) << '\n';

  return 0;
}