Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const long long wallet = 1E15;

int n, m;
int s, t;
long long in[100000], out[100000];
long long u[100000], v[100000], a[100000], b[100000];
long long ans[100000];

vector<int> edge_index[100000];

int dijkstra(int start, long long *cost, long long *w) {
  for (int i = 0; i < n; i++)
    cost[i] = wallet;

  priority_queue<pair<long long, int>> pq;

  cost[start] = 0;
  pq.push(make_pair(0, start));

  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();

    if (cost[p.second] < p.first)
      continue;
    //      cout << p.second <<"(" << cost[p.second]<<"):"<<endl;
    for (int item : edge_index[p.second]) {
      int dist;
      if (u[item] == p.second)
        dist = v[item];
      else
        dist = u[item];

      if (p.first + w[item] < cost[dist]) {
        cost[dist] = p.first + w[item];
        pq.push(make_pair(cost[dist], dist));
      }
      //         cout << dist <<":"<<p.first+w[item]<<endl;
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;

  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;

    edge_index[u[i]].push_back(i);
    edge_index[v[i]].push_back(i);
    //      cout << u[i] <<" --  "<<i<<endl;;
    //      cout << v[i] <<" --  "<<i<<endl;;
  }

  dijkstra(s - 1, in, a);
  dijkstra(t - 1, out, b);

  long long bef_ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = max(bef_ans, wallet - in[i] - out[i]);
    bef_ans = ans[i];
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
    //      cout << in[i] << " " << out[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const long long wallet = 1E15;

int n, m;
int s, t;
long long in[100000], out[100000];
long long u[100000], v[100000], a[100000], b[100000];
long long ans[100000];

vector<int> edge_index[100000];

int dijkstra(int start, long long *cost, long long *w) {
  for (int i = 0; i < n; i++)
    cost[i] = wallet;

  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;

  cost[start] = 0;
  pq.push(make_pair(0, start));

  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();

    if (cost[p.second] < p.first)
      continue;
    //      cout << p.second <<"(" << cost[p.second]<<"):"<<endl;
    for (int item : edge_index[p.second]) {
      int dist;
      if (u[item] == p.second)
        dist = v[item];
      else
        dist = u[item];

      if (p.first + w[item] < cost[dist]) {
        cost[dist] = p.first + w[item];
        pq.push(make_pair(cost[dist], dist));
      }
      //         cout << dist <<":"<<p.first+w[item]<<endl;
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;

  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;

    edge_index[u[i]].push_back(i);
    edge_index[v[i]].push_back(i);
    //      cout << u[i] <<" --  "<<i<<endl;;
    //      cout << v[i] <<" --  "<<i<<endl;;
  }

  dijkstra(s - 1, in, a);
  dijkstra(t - 1, out, b);

  long long bef_ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = max(bef_ans, wallet - in[i] - out[i]);
    bef_ans = ans[i];
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
    //      cout << in[i] << " " << out[i] << endl;
  }

  return 0;
}