Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int n, m, s, t;
vector<pii> g[2][112345]; // 0:yen, 1:snuuk
ll dist[2][112345];
ll ans[112345];

struct Edge {
  int u, v, a, b;
};

struct Edge edge[112345];

void dijkstra(int st, int mode) {
  fill(dist[mode], dist[mode + 1], INF);

  priority_queue<pll> pq; // cost, pos
  pq.push(pll(0, st));
  dist[mode][st] = 0;
  while (!pq.empty()) {
    pll cur = pq.top();
    pq.pop();
    int curpos = cur.se;
    ll curcost = cur.fi;

    if (dist[mode][curpos] < curcost)
      continue;

    REP(i, g[mode][curpos].size()) {
      int nextpos = g[mode][curpos][i].fi;
      ll nextcost = curcost + g[mode][curpos][i].se;

      if (chmin(dist[mode][nextpos], nextcost)) {
        pq.push(pll(nextcost, nextpos));
      }
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;
  s--;
  t--;
  REP(i, m) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    u--;
    v--;
    edge[i] = (Edge){u, v, a, b};
    g[0][u].push_back(pii(v, a));
    g[0][v].push_back(pii(u, a));
    g[1][u].push_back(pii(v, b));
    g[1][v].push_back(pii(u, b));
  }

  dijkstra(s, 0);
  dijkstra(t, 1);

  ll prmx = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll cur = 1e15;
    cur -= dist[0][i];
    cur -= dist[1][i];
    chmax(prmx, cur);
    ans[i] = prmx;
  }

  REP(i, n) printf("%lld\n", ans[i]);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int n, m, s, t;
vector<pii> g[2][112345]; // 0:yen, 1:snuuk
ll dist[2][112345];
ll ans[112345];

struct Edge {
  int u, v, a, b;
};

struct Edge edge[112345];

void dijkstra(int st, int mode) {
  fill(dist[mode], dist[mode + 1], INF);

  priority_queue<pll, vector<pll>, greater<pll>> pq; // cost, pos
  pq.push(pll(0, st));
  dist[mode][st] = 0;
  while (!pq.empty()) {
    pll cur = pq.top();
    pq.pop();
    int curpos = cur.se;
    ll curcost = cur.fi;

    if (dist[mode][curpos] < curcost)
      continue;

    REP(i, g[mode][curpos].size()) {
      int nextpos = g[mode][curpos][i].fi;
      ll nextcost = curcost + g[mode][curpos][i].se;

      if (chmin(dist[mode][nextpos], nextcost)) {
        pq.push(pll(nextcost, nextpos));
      }
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;
  s--;
  t--;
  REP(i, m) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    u--;
    v--;
    edge[i] = (Edge){u, v, a, b};
    g[0][u].push_back(pii(v, a));
    g[0][v].push_back(pii(u, a));
    g[1][u].push_back(pii(v, b));
    g[1][v].push_back(pii(u, b));
  }

  dijkstra(s, 0);
  dijkstra(t, 1);

  ll prmx = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll cur = 1e15;
    cur -= dist[0][i];
    cur -= dist[1][i];
    chmax(prmx, cur);
    ans[i] = prmx;
  }

  REP(i, n) printf("%lld\n", ans[i]);

  return 0;
}