Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

struct Edge {
  int from;
  int to;
  ll cost;
};

vector<ll> dijkstra(vector<vector<Edge>> &G, int start) {
  priority_queue<pair<ll, int>> Q;
  Q.push(mp(0, start));
  vector<ll> ret(G.size(), 1LL << 61);
  while (!Q.empty()) {
    pair<ll, int> P = Q.top();
    Q.pop();
    int p = P.second;
    ll d = P.first;
    if (ret[p] <= d)
      continue;
    ret[p] = d;
    for (int i = 0; i < G[p].size(); i++) {
      int to = G[p][i].to;
      if (d + G[p][i].cost < ret[to]) {
        Q.push(mp(d + G[p][i].cost, to));
      }
    }
  }
  return ret;
}

int main() {
  int N, M, S, T;
  cin >> N >> M >> S >> T;
  S--, T--;
  vector<vector<Edge>> G1(N), G2(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    u--, v--;

    Edge e1 = {u, v, a};
    Edge e2 = {v, u, a};
    G1[u].push_back(e1);
    G1[v].push_back(e2);

    Edge e3 = {u, v, b};
    Edge e4 = {v, u, b};
    G2[u].push_back(e3);
    G2[v].push_back(e4);
  }
  vector<ll> d1 = dijkstra(G1, S);
  vector<ll> d2 = dijkstra(G2, T);

  vector<ll> ans(N);
  ll mi = 1LL << 61;
  for (int i = N - 1; i >= 0; i--) {
    mi = min(mi, d1[i] + d2[i]);
    ans[i] = mi;
  }

  for (int i = 0; i < N; i++) {
    cout << 1000000000000000LL - ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

struct Edge {
  int from;
  int to;
  ll cost;
};

vector<ll> dijkstra(vector<vector<Edge>> &G, int start) {
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      Q;
  Q.push(mp(0, start));
  vector<ll> ret(G.size(), 1LL << 61);
  while (!Q.empty()) {
    pair<ll, int> P = Q.top();
    Q.pop();
    int p = P.second;
    ll d = P.first;
    if (ret[p] <= d)
      continue;
    ret[p] = d;
    for (int i = 0; i < G[p].size(); i++) {
      int to = G[p][i].to;
      if (d + G[p][i].cost < ret[to]) {
        Q.push(mp(d + G[p][i].cost, to));
      }
    }
  }
  return ret;
}

int main() {
  int N, M, S, T;
  cin >> N >> M >> S >> T;
  S--, T--;
  vector<vector<Edge>> G1(N), G2(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    u--, v--;

    Edge e1 = {u, v, a};
    Edge e2 = {v, u, a};
    G1[u].push_back(e1);
    G1[v].push_back(e2);

    Edge e3 = {u, v, b};
    Edge e4 = {v, u, b};
    G2[u].push_back(e3);
    G2[v].push_back(e4);
  }
  vector<ll> d1 = dijkstra(G1, S);
  vector<ll> d2 = dijkstra(G2, T);

  vector<ll> ans(N);
  ll mi = 1LL << 61;
  for (int i = N - 1; i >= 0; i--) {
    mi = min(mi, d1[i] + d2[i]);
    ans[i] = mi;
  }

  for (int i = 0; i < N; i++) {
    cout << 1000000000000000LL - ans[i] << endl;
  }
  return 0;
}