Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;

  V<V<P>> yen(n);
  V<V<P>> snk(n);

  rep(i, m) {

    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    yen[u].push_back(P(a, v));
    yen[v].push_back(P(a, u));
    snk[u].push_back(P(b, v));
    snk[v].push_back(P(b, u));
  }

  V<ll> dyen(n, LINF), dsnk(n, LINF);
  dyen[s] = 0;
  dsnk[t] = 0;

  priority_queue<P> pq;

  pq.push(P(0, s));

  while (!pq.empty()) {

    P p = pq.top();
    pq.pop();
    int v = p.second;
    ll vd = p.first;
    if (vd > dyen[v])
      continue;

    rep(i, yen[v].size()) {
      int vv = yen[v][i].second;
      int vvd = yen[v][i].first;
      if (dyen[vv] <= dyen[v] + vvd)
        continue;
      dyen[vv] = dyen[v] + vvd;
      pq.push(P(dyen[vv], vv));
    }
  }

  pq.push(P(0, t));

  while (!pq.empty()) {

    P p = pq.top();
    pq.pop();
    int v = p.second;
    ll vd = p.first;
    if (vd > dsnk[v])
      continue;

    rep(i, snk[v].size()) {
      int vv = snk[v][i].second;
      int vvd = snk[v][i].first;
      if (dsnk[vv] <= dsnk[v] + vvd)
        continue;
      dsnk[vv] = dsnk[v] + vvd;
      pq.push(P(dsnk[vv], vv));
    }
  }

  V<ll> ans(n + 1, LINF);

  rep(i, n) ans[n - 1 - i] = min(ans[n - i], dyen[n - 1 - i] + dsnk[n - 1 - i]);
  rep(i, n) cout << (ll)1e15 - ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;

  V<V<P>> yen(n);
  V<V<P>> snk(n);

  rep(i, m) {

    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    yen[u].push_back(P(a, v));
    yen[v].push_back(P(a, u));
    snk[u].push_back(P(b, v));
    snk[v].push_back(P(b, u));
  }

  V<ll> dyen(n, LINF), dsnk(n, LINF);
  dyen[s] = 0;
  dsnk[t] = 0;

  priority_queue<P, V<P>, greater<P>> pq;

  pq.push(P(0, s));

  while (!pq.empty()) {

    P p = pq.top();
    pq.pop();
    int v = p.second;
    ll vd = p.first;
    if (vd > dyen[v])
      continue;

    rep(i, yen[v].size()) {
      int vv = yen[v][i].second;
      int vvd = yen[v][i].first;
      if (dyen[vv] <= dyen[v] + vvd)
        continue;
      dyen[vv] = dyen[v] + vvd;
      pq.push(P(dyen[vv], vv));
    }
  }

  pq.push(P(0, t));

  while (!pq.empty()) {

    P p = pq.top();
    pq.pop();
    int v = p.second;
    ll vd = p.first;
    if (vd > dsnk[v])
      continue;

    rep(i, snk[v].size()) {
      int vv = snk[v][i].second;
      int vvd = snk[v][i].first;
      if (dsnk[vv] <= dsnk[v] + vvd)
        continue;
      dsnk[vv] = dsnk[v] + vvd;
      pq.push(P(dsnk[vv], vv));
    }
  }

  V<ll> ans(n + 1, LINF);

  rep(i, n) ans[n - 1 - i] = min(ans[n - i], dyen[n - 1 - i] + dsnk[n - 1 - i]);
  rep(i, n) cout << (ll)1e15 - ans[i] << endl;
}