Problem p03305 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                                                           \
  cerr << #v << ":";                                                           \
  rep(i, v.size()) cerr << " " << v[i];                                        \
  cerr << endl
using namespace std;
int MOD = 1000000007;
int n, m, s, t;
#define MAX_V 10010
struct edge {
  int to, cost;
};
typedef pair<int, int> pii;
int V;
vector<edge> G[2][MAX_V];
int d[2][MAX_V];
void dijkstra(int s, int x) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  rep(i, V) d[x][i] = INF;
  // fill(d[x],d[x]+V,INF);
  d[x][s] = 0;
  que.push(pii(0, s));
  while (!que.empty()) {
    pii p = que.top();
    que.pop();
    int v = p.se;
    if (d[x][v] < p.fi)
      continue;
    rep(i, G[x][v].size()) {
      edge e = G[x][v][i];
      if (d[x][e.to] > d[x][v] + e.cost) {
        d[x][e.to] = d[x][v] + e.cost;
        que.push(pii(d[x][e.to], e.to));
      }
    }
  }
}
vector<pair<int, int>> cst;

signed main() {
  cin >> n >> m >> s >> t;
  s--;
  t--;
  V = n;
  rep(i, m) { // m は edge数
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge e1 = {u, a};
    edge e2 = {v, a};
    G[0][v].pb(e1);
    G[0][u].pb(e2);
    edge e3 = {u, b};
    edge e4 = {v, b};
    G[1][v].pb(e3);
    G[1][u].pb(e4);
  }
  dijkstra(s, 0); // yen
  dijkstra(t, 1); // snuke

  rep(i, n) { cst.pb(MP(d[0][i] + d[1][i], i)); }

  SORT(cst);
  int num = 0;
  rep(i, n) {
    while (cst[num].se < i) {
      num++;
    }
    cout << 1000000000000000 - cst[num].fi << endl;
  }

  return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc064.contest.atcoder.jp/tasks/arc064_c
// rm -r -f test;oj dl
// http://soundhound2018-summer-qual.contest.atcoder.jp/tasks/soundhound2018_summer_qual_d

Fixed submission:
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                                                           \
  cerr << #v << ":";                                                           \
  rep(i, v.size()) cerr << " " << v[i];                                        \
  cerr << endl
using namespace std;
int MOD = 1000000007;
int n, m, s, t;
#define MAX_V 100010
struct edge {
  int to, cost;
};
typedef pair<int, int> pii;
int V;
vector<edge> G[2][MAX_V];
int d[2][MAX_V];
void dijkstra(int s, int x) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  rep(i, V) d[x][i] = INF;
  // fill(d[x],d[x]+V,INF);
  d[x][s] = 0;
  que.push(pii(0, s));
  while (!que.empty()) {
    pii p = que.top();
    que.pop();
    int v = p.se;
    if (d[x][v] < p.fi)
      continue;
    rep(i, G[x][v].size()) {
      edge e = G[x][v][i];
      if (d[x][e.to] > d[x][v] + e.cost) {
        d[x][e.to] = d[x][v] + e.cost;
        que.push(pii(d[x][e.to], e.to));
      }
    }
  }
}
vector<pair<int, int>> cst;

signed main() {
  cin >> n >> m >> s >> t;
  s--;
  t--;
  V = n;
  rep(i, m) { // m は edge数
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge e1 = {u, a};
    edge e2 = {v, a};
    G[0][v].pb(e1);
    G[0][u].pb(e2);
    edge e3 = {u, b};
    edge e4 = {v, b};
    G[1][v].pb(e3);
    G[1][u].pb(e4);
  }
  dijkstra(s, 0); // yen
  dijkstra(t, 1); // snuke

  rep(i, n) { cst.pb(MP(d[0][i] + d[1][i], i)); }

  SORT(cst);
  int num = 0;
  rep(i, n) {
    while (cst[num].se < i) {
      num++;
    }
    cout << 1000000000000000 - cst[num].fi << endl;
  }

  return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc064.contest.atcoder.jp/tasks/arc064_c
// rm -r -f test;oj dl
// http://soundhound2018-summer-qual.contest.atcoder.jp/tasks/soundhound2018_summer_qual_d