Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;

int n;
struct edge {
  int to, cost;
};
const int MAX_N = 100010;
vector<edge> G[MAX_N];
ll dist[MAX_N];
vector<edge> G2[MAX_N];
ll dist2[MAX_N];

void dijkstra(int s) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  fill(dist, dist + n, inf);
  dist[s] = 0;
  que.push(pii(0, s));
  while (!que.empty()) {
    pii p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(pii(dist[e.to], e.to));
      }
    }
  }
}
void dijkstra2(int s) {
  priority_queue<pii, vector<pii>, greater<pii>> que2;
  fill(dist2, dist2 + n, inf);
  dist2[s] = 0;
  que2.push(pii(0, s));
  while (!que2.empty()) {
    pii p = que2.top();
    que2.pop();
    int v = p.second;
    if (dist2[v] < p.first)
      continue;
    for (int i = 0; i < G2[v].size(); i++) {
      edge e = G2[v][i];
      if (dist2[e.to] > dist2[v] + e.cost) {
        dist2[e.to] = dist2[v] + e.cost;
        que2.push(pii(dist2[e.to], e.to));
      }
    }
  }
}

int main() {
  int m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  rep(i, m) {
    int a, b, c1, c2;
    cin >> a >> b >> c1 >> c2;
    a--;
    b--;
    G[a].push_back({b, c1});
    G[b].push_back({a, c1});
    G2[a].push_back({b, c2});
    G2[b].push_back({a, c2});
  }
  vector<ll> ans(n);
  dijkstra(s);
  dijkstra2(t);
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = dist[i] + dist2[i];
    if (i < n - 1)
      chmin(ans[i], ans[i + 1]);
  }
  rep(i, n) { cout << (ll)1e15 - ans[i] << endl; }
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;

int n;
struct edge {
  int to, cost;
};
const int MAX_N = 100010;
vector<edge> G[MAX_N];
ll dist[MAX_N];
vector<edge> G2[MAX_N];
ll dist2[MAX_N];

void dijkstra(int s) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  fill(dist, dist + n, inf);
  dist[s] = 0;
  que.push(pii(0, s));
  while (!que.empty()) {
    pii p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(pii(dist[e.to], e.to));
      }
    }
  }
}
void dijkstra2(int s) {
  priority_queue<pii, vector<pii>, greater<pii>> que2;
  fill(dist2, dist2 + n, inf);
  dist2[s] = 0;
  que2.push(pii(0, s));
  while (!que2.empty()) {
    pii p = que2.top();
    que2.pop();
    int v = p.second;
    if (dist2[v] < p.first)
      continue;
    for (int i = 0; i < G2[v].size(); i++) {
      edge e = G2[v][i];
      if (dist2[e.to] > dist2[v] + e.cost) {
        dist2[e.to] = dist2[v] + e.cost;
        que2.push(pii(dist2[e.to], e.to));
      }
    }
  }
}

int main() {
  int m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  rep(i, m) {
    int a, b, c1, c2;
    cin >> a >> b >> c1 >> c2;
    a--;
    b--;
    G[a].push_back({b, c1});
    G[b].push_back({a, c1});
    G2[a].push_back({b, c2});
    G2[b].push_back({a, c2});
  }
  vector<ll> ans(n);
  dijkstra(s);
  dijkstra2(t);
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = dist[i] + dist2[i];
    if (i < n - 1)
      chmin(ans[i], ans[i + 1]);
  }
  rep(i, n) { cout << (ll)1e15 - ans[i] << endl; }
}