Problem p03305 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e16;
int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector<vector<P>> e_yen(n + 1);
  vector<vector<P>> e_snu(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    e_yen[u].push_back(P(a, v));
    e_yen[v].push_back(P(a, u));
    e_snu[u].push_back(P(b, v));
    e_snu[v].push_back(P(b, u));
  }

  vector<ll> yen(n + 1);
  vector<ll> snu(n + 1);
  for (int i = 0; i <= n; i++) {
    yen[i] = INF;
    snu[i] = INF;
  }
  yen[s] = 0;
  snu[t] = 0;

  priority_queue<P, vector<P>, greater<P>> yenq;
  yenq.push(P(0, s));
  while (!yenq.empty()) {
    P p = yenq.top();
    yenq.pop();
    if (yen[p.second] < p.first)
      continue;
    for (auto nx : e_yen[p.second]) {
      if (yen[nx.second] > yen[p.second] + nx.first) {
        yen[nx.second] = yen[p.second] + nx.first;
        yenq.push(P(yen[nx.second], nx.second));
      }
    }
  }
  priority_queue<P, vector<P>, greater<P>> snuq;
  snuq.push(P(0, t));
  while (!snuq.empty()) {
    P p = snuq.top();
    snuq.pop();
    if (snu[p.second] < p.first)
      continue;
    for (auto nx : e_snu[p.second]) {
      if (snu[nx.second] > snu[p.second] + nx.first) {
        snu[nx.second] = snu[p.second] + nx.first;
        snuq.push(P(snu[nx.second], nx.second));
      }
    }
  }

  vector<ll> ac(n);
  ac[n] = INF;
  for (int i = n - 1; i >= 0; i--) {
    ac[i] = min(ac[i + 1], yen[i + 1] + snu[i + 1]);
  }

  for (int i = 0; i < n; i++) {
    ll ans = 1e15 - ac[i];
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e16;
int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector<vector<P>> e_yen(n + 1);
  vector<vector<P>> e_snu(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    e_yen[u].push_back(P(a, v));
    e_yen[v].push_back(P(a, u));
    e_snu[u].push_back(P(b, v));
    e_snu[v].push_back(P(b, u));
  }

  vector<ll> yen(n + 1);
  vector<ll> snu(n + 1);
  for (int i = 0; i <= n; i++) {
    yen[i] = INF;
    snu[i] = INF;
  }
  yen[s] = 0;
  snu[t] = 0;

  priority_queue<P, vector<P>, greater<P>> yenq;
  yenq.push(P(0, s));
  while (!yenq.empty()) {
    P p = yenq.top();
    yenq.pop();
    if (yen[p.second] < p.first)
      continue;
    for (auto nx : e_yen[p.second]) {
      if (yen[nx.second] > yen[p.second] + nx.first) {
        yen[nx.second] = yen[p.second] + nx.first;
        yenq.push(P(yen[nx.second], nx.second));
      }
    }
  }
  priority_queue<P, vector<P>, greater<P>> snuq;
  snuq.push(P(0, t));
  while (!snuq.empty()) {
    P p = snuq.top();
    snuq.pop();
    if (snu[p.second] < p.first)
      continue;
    for (auto nx : e_snu[p.second]) {
      if (snu[nx.second] > snu[p.second] + nx.first) {
        snu[nx.second] = snu[p.second] + nx.first;
        snuq.push(P(snu[nx.second], nx.second));
      }
    }
  }

  vector<ll> ac(n + 1);
  ac[n] = INF;
  for (int i = n - 1; i >= 0; i--) {
    ac[i] = min(ac[i + 1], yen[i + 1] + snu[i + 1]);
  }

  for (int i = 0; i < n; i++) {
    ll ans = 1e15 - ac[i];
    cout << ans << endl;
  }
}