Problem p02868 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
  ll n, m;
  cin >> n >> m;

  vvpll G(n);
  rep(v, n - 1) { G[v + 1].pb(make_pair(v, 0)); }
  rep(loop, m) {
    ll L, R, c;
    cin >> L >> R >> c;
    L--;
    R--;
    G[L].pb(make_pair(R, c));
    G[R].pb(make_pair(L, c));
  }

  // ダイクストラ法。計算量はO((V+E)*log(V))
  const ll sv = 0; // 始点となる頂点。デフォルトでは0
  vl dist(n, INF); // dist[v] : 頂点svから頂点vへの最短距離
  priority_queue<P, vector<P>, greater<P>> prQ;
  dist[sv] = 0;
  prQ.push(make_pair(sv, 0)); // (頂点番号, 頂点svからの最短距離)
  while (!prQ.empty()) {
    auto p1 = prQ.top();
    prQ.pop();
    ll v = p1.first;
    if (dist[v] < p1.second) {
      continue;
    }
    for (auto p2 : G[v]) {
      ll u = p2.first;
      ll cost = p2.second;
      if (dist[u] > dist[v] + cost) {
        dist[u] = dist[v] + cost;
        prQ.push(make_pair(u, dist[u]));
      }
    }
  }

  if (dist[n - 1] == INF) {
    out(-1);
  } else {
    out(dist[n - 1]);
  }

  re0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
  ll n, m;
  cin >> n >> m;

  vvpll G(n);
  rep(v, n - 1) { G[v + 1].pb(make_pair(v, 0)); }
  rep(loop, m) {
    ll L, R, c;
    cin >> L >> R >> c;
    L--;
    R--;
    G[L].pb(make_pair(R, c));
  }

  // ダイクストラ法。計算量はO((V+E)*log(V))
  const ll sv = 0; // 始点となる頂点。デフォルトでは0
  vl dist(n, INF); // dist[v] : 頂点svから頂点vへの最短距離
  priority_queue<P, vector<P>, greater<P>> prQ;
  dist[sv] = 0;
  prQ.push(make_pair(sv, 0)); // (頂点番号, 頂点svからの最短距離)
  while (!prQ.empty()) {
    auto p1 = prQ.top();
    prQ.pop();
    ll v = p1.first;
    if (dist[v] < p1.second) {
      continue;
    }
    for (auto p2 : G[v]) {
      ll u = p2.first;
      ll cost = p2.second;
      if (dist[u] > dist[v] + cost) {
        dist[u] = dist[v] + cost;
        prQ.push(make_pair(u, dist[u]));
      }
    }
  }

  if (dist[n - 1] == INF) {
    out(-1);
  } else {
    out(dist[n - 1]);
  }

  re0;
}