Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, M, S, T;
  cin >> N >> M >> S >> T;
  S--;
  T--;
  vector<vector<pair<int64_t, int64_t>>> GY(N,
                                            vector<pair<int64_t, int64_t>>(0));
  vector<vector<pair<int64_t, int64_t>>> GS(N,
                                            vector<pair<int64_t, int64_t>>(0));
  pair<int64_t, int64_t> P;
  for (int i = 0; i < M; i++) {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    P = make_pair(b, c);
    GY.at(a).push_back(P);
    P = make_pair(a, c);
    GY.at(b).push_back(P);
    P = make_pair(b, d);
    GS.at(a).push_back(P);
    P = make_pair(a, d);
    GS.at(b).push_back(P);
  }

  int64_t INF = 1e18;
  vector<int64_t> D1(N, INF); // startからyenでの距離
  vector<int64_t> D2(N, INF); // goalからsnukeでの距離

  priority_queue<pair<int64_t, int64_t>> PQ;
  P = make_pair(0, S);
  PQ.push(P);
  D1.at(S) = 0;
  while (PQ.size()) {
    P = PQ.top();
    int64_t x = P.first;
    int64_t y = P.second;
    PQ.pop();
    if (D1.at(y) < x) {
      continue;
    }
    for (int i = 0; i < GY.at(y).size(); i++) {
      P = GY.at(y).at(i);
      int64_t a = P.first;  // to
      int64_t b = P.second; // cost
      if (D1.at(a) > x + b) {
        D1.at(a) = x + b;
        P = make_pair(D1.at(a), a);
        PQ.push(P);
      }
    }
  }

  P = make_pair(0, T);
  PQ.push(P);
  D2.at(T) = 0;
  while (PQ.size()) {
    P = PQ.top();
    int64_t x = P.first;
    int64_t y = P.second;
    PQ.pop();
    if (D2.at(y) < x) {
      continue;
    }
    for (int i = 0; i < GS.at(y).size(); i++) {
      P = GS.at(y).at(i);
      int64_t a = P.first;  // to
      int64_t b = P.second; // cost
      if (D2.at(a) > x + b) {
        D2.at(a) = x + b;
        P = make_pair(D2.at(a), a);
        PQ.push(P);
      }
    }
  }

  vector<int64_t> use(N);
  for (int i = 0; i < N; i++) {
    use.at(i) = D1.at(i) + D2.at(i);
  }

  int64_t MIN = 1e18;
  vector<int64_t> ans(N);
  for (int i = N - 1; i >= 0; i--) {
    MIN = min(MIN, use.at(i));
    ans.at(i) = 1e15 - MIN;
  }

  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, M, S, T;
  cin >> N >> M >> S >> T;
  S--;
  T--;
  vector<vector<pair<int64_t, int64_t>>> GY(N,
                                            vector<pair<int64_t, int64_t>>(0));
  vector<vector<pair<int64_t, int64_t>>> GS(N,
                                            vector<pair<int64_t, int64_t>>(0));
  pair<int64_t, int64_t> P;
  for (int i = 0; i < M; i++) {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    P = make_pair(b, c);
    GY.at(a).push_back(P);
    P = make_pair(a, c);
    GY.at(b).push_back(P);
    P = make_pair(b, d);
    GS.at(a).push_back(P);
    P = make_pair(a, d);
    GS.at(b).push_back(P);
  }

  int64_t INF = 1e18;
  vector<int64_t> D1(N, INF); // startからyenでの距離
  vector<int64_t> D2(N, INF); // goalからsnukeでの距離

  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>,
                 greater<pair<int64_t, int64_t>>>
      PQ;
  P = make_pair(0, S);
  PQ.push(P);
  D1.at(S) = 0;
  while (PQ.size()) {
    P = PQ.top();
    int64_t x = P.first;
    int64_t y = P.second;
    PQ.pop();
    if (D1.at(y) < x) {
      continue;
    }
    for (int i = 0; i < GY.at(y).size(); i++) {
      P = GY.at(y).at(i);
      int64_t a = P.first;  // to
      int64_t b = P.second; // cost
      if (D1.at(a) > x + b) {
        D1.at(a) = x + b;
        P = make_pair(D1.at(a), a);
        PQ.push(P);
      }
    }
  }

  P = make_pair(0, T);
  PQ.push(P);
  D2.at(T) = 0;
  while (PQ.size()) {
    P = PQ.top();
    int64_t x = P.first;
    int64_t y = P.second;
    PQ.pop();
    if (D2.at(y) < x) {
      continue;
    }
    for (int i = 0; i < GS.at(y).size(); i++) {
      P = GS.at(y).at(i);
      int64_t a = P.first;  // to
      int64_t b = P.second; // cost
      if (D2.at(a) > x + b) {
        D2.at(a) = x + b;
        P = make_pair(D2.at(a), a);
        PQ.push(P);
      }
    }
  }

  vector<int64_t> use(N);
  for (int i = 0; i < N; i++) {
    use.at(i) = D1.at(i) + D2.at(i);
  }

  int64_t MIN = 1e18;
  vector<int64_t> ans(N);
  for (int i = N - 1; i >= 0; i--) {
    MIN = min(MIN, use.at(i));
    ans.at(i) = 1e15 - MIN;
  }

  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}