Problem p02868 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

// computational complexity : O(E*logV)

struct edge {
  int to;
  long long int cost;
};

int V, E; // number of (vertices, edges)
vector<vector<edge>> graph;
vector<long long int> d; // shortest distances

void Dijkstra(int s) { // s = starting point
  priority_queue<
      pair<int, int> // temporarily keeping (shortest distance, vertex)
      ,
      vector<pair<int, int>>, greater<pair<int, int>> // shorter ones first
      >
      pq;

  // initialize (INF)
  for (int i = 0; i < V; i++) {
    d[i] = INF;
  }
  d[s] = 0;
  pq.push({0, s});

  // search
  pair<long long int, int> current; // (shortest-distance confirmed, vertex)
  while (!pq.empty()) {
    current = pq.top();
    pq.pop();

    int v = current.second;
    if (d[v] < current.first) {
      continue; // ignore (not the shortest path)
    }
    // else (need to check)
    for (edge e : graph[v]) { // adjacent nodes
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; // update minimum cost
        pq.push({d[e.to], e.to});
      }
    }
  }
}

int main() {
  cin >> V >> E;
  graph.resize(V);
  d.resize(V);
  for (int i = 0; i + 1 < V; i++) {
    graph[i + 1].push_back({i, 0});
  }

  for (int i = 0; i < E; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l -= 1;
    r -= 1;
    graph[l].push_back({r, c});
  }

  Dijkstra(0); // starting from s
  if (d[V - 1] != INF)
    cout << d[V - 1] << endl;
  if (d[V - 1] == INF)
    cout << -1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

// computational complexity : O(E*logV)

struct edge {
  int to;
  long long int cost;
};

int V, E; // number of (vertices, edges)
vector<vector<edge>> graph;
vector<long long int> d; // shortest distances

void Dijkstra(int s) {                    // s = starting point
  priority_queue<pair<long long int, int> // temporarily keeping (shortest
                                          // distance, vertex)
                 ,
                 vector<pair<long long int, int>>,
                 greater<pair<long long int, int>> // shorter ones first
                 >
      pq;

  // initialize (INF)
  for (int i = 0; i < V; i++) {
    d[i] = INF;
  }
  d[s] = 0;
  pq.push({0, s});

  // search
  pair<long long int, int> current; // (shortest-distance confirmed, vertex)
  while (!pq.empty()) {
    current = pq.top();
    pq.pop();

    int v = current.second;
    if (d[v] < current.first) {
      continue; // ignore (not the shortest path)
    }
    // else (need to check)
    for (edge e : graph[v]) { // adjacent nodes
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; // update minimum cost
        pq.push({d[e.to], e.to});
      }
    }
  }
}

int main() {
  cin >> V >> E;
  graph.resize(V);
  d.resize(V);
  for (int i = 0; i + 1 < V; i++) {
    graph[i + 1].push_back({i, 0});
  }

  for (int i = 0; i < E; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l -= 1;
    r -= 1;
    graph[l].push_back({r, c});
  }

  Dijkstra(0); // starting from s
  if (d[V - 1] != INF)
    cout << d[V - 1] << endl;
  if (d[V - 1] == INF)
    cout << -1 << endl;
  return 0;
}