Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
// I SELL YOU...!
#include <algorithm>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#define FIRST (ll)(1e15)
#define MAX_N 110000
#define INF 10000000000000000
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
typedef struct {
  ll to, cost;
} edge;
vector<edge> MG[MAX_N], SG[MAX_N];
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main() {
  init_io();
  ll n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<ll> u(m), v(m), a(m), b(m), dbest(MAX_N, INF), sbest(MAX_N, INF);
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    MG[u[i]].push_back({v[i], a[i]});
    MG[v[i]].push_back({u[i], a[i]});

    SG[u[i]].push_back({v[i], b[i]});
    SG[v[i]].push_back({u[i], b[i]});
  }
  priority_queue<P> que;
  que.push(P(0, s));
  while (!que.empty()) {
    P tmp = que.top();
    que.pop();
    ll d = tmp.first;
    ll v = tmp.second;
    if (dbest[v] <= d)
      continue;
    dbest[v] = d;
    for (auto nv : MG[v]) {
      ll nd = nv.cost + d;
      if (dbest[nv.to] > nd) {
        que.push(P(nv.cost + d, nv.to));
      }
    }
  }

  que.push(P(0, t));
  while (!que.empty()) {
    P tmp = que.top();
    que.pop();
    ll d = tmp.first;
    ll v = tmp.second;
    if (sbest[v] <= d)
      continue;
    sbest[v] = d;
    for (auto nv : SG[v]) {
      ll nd = nv.cost + d;
      if (sbest[nv.to] > nd) {
        que.push(P(nv.cost + d, nv.to));
      }
    }
  }
  vector<ll> ans;
  ll best = 0;
  for (int i = n - 1; i >= 0; i--) {
    best = max(best, FIRST - dbest[i] - sbest[i]);
    ans.push_back(best);
  }
  reverse(ans.begin(), ans.end());
  for (auto a : ans) {
    cout << a << endl;
  }
}


Fixed submission:
// I SELL YOU...!
#include <algorithm>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#define FIRST (ll)(1e15)
#define MAX_N 110000
#define INF 10000000000000000
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
typedef struct {
  ll to, cost;
} edge;
vector<edge> MG[MAX_N], SG[MAX_N];
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main() {
  init_io();
  ll n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<ll> u(m), v(m), a(m), b(m), dbest(MAX_N, INF), sbest(MAX_N, INF);
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    MG[u[i]].push_back({v[i], a[i]});
    MG[v[i]].push_back({u[i], a[i]});

    SG[u[i]].push_back({v[i], b[i]});
    SG[v[i]].push_back({u[i], b[i]});
  }
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  while (!que.empty()) {
    P tmp = que.top();
    que.pop();
    ll d = tmp.first;
    ll v = tmp.second;
    if (dbest[v] <= d)
      continue;
    dbest[v] = d;
    for (auto nv : MG[v]) {
      ll nd = nv.cost + d;
      if (dbest[nv.to] > nd) {
        que.push(P(nv.cost + d, nv.to));
      }
    }
  }

  que.push(P(0, t));
  while (!que.empty()) {
    P tmp = que.top();
    que.pop();
    ll d = tmp.first;
    ll v = tmp.second;
    if (sbest[v] <= d)
      continue;
    sbest[v] = d;
    for (auto nv : SG[v]) {
      ll nd = nv.cost + d;
      if (sbest[nv.to] > nd) {
        que.push(P(nv.cost + d, nv.to));
      }
    }
  }
  vector<ll> ans;
  ll best = 0;
  for (int i = n - 1; i >= 0; i--) {
    best = max(best, FIRST - dbest[i] - sbest[i]);
    ans.push_back(best);
  }
  reverse(ans.begin(), ans.end());
  for (auto a : ans) {
    cout << a << endl;
  }
}