Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int NMAX = 100001;
const long long INF = 1e18;

struct edge {
  int to;
  int en;
  int snuuk;
};

vector<long long> de(NMAX, INF);
vector<long long> ds(NMAX, INF);
vector<pair<long long, int>> d;
vector<vector<edge>> G(NMAX);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int n, m, start, goal;
  cin >> n >> m >> start >> goal;
  vector<long long> ans(n, INF);
  start--;
  goal--;
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge e1 = {v, a, b};
    edge e2 = {u, a, b};
    G[u].push_back(e1);
    G[v].push_back(e2);
  }
  // start to goal
  priority_queue<pair<long long, int>> pq;
  pair<long long, int> p = make_pair(0, start);
  de[start] = 0;
  pq.push(p);
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second;
    if (minn > de[v])
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (de[G[v][i].to] > G[v][i].en + minn) {
        de[G[v][i].to] = G[v][i].en + minn;
        pq.emplace(de[G[v][i].to], G[v][i].to);
      }
    }
  }
  // goal to start
  p = make_pair(0, goal);
  ds[goal] = 0;
  pq.push(p);
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second;
    if (minn > ds[v])
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (ds[G[v][i].to] > G[v][i].snuuk + minn) {
        ds[G[v][i].to] = G[v][i].snuuk + minn;
        pq.emplace(ds[G[v][i].to], G[v][i].to);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    d.push_back(make_pair(de[i] + ds[i], i));
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < n; i++) {
    long long minn = d[i].first;
    long long t = d[i].second;
    for (int j = t; j >= 0; j--) {
      if (ans[j] == INF)
        ans[j] = minn;
      else
        break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (long long)1e15 - ans[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int NMAX = 100001;
const long long INF = 1e18;

struct edge {
  int to;
  int en;
  int snuuk;
};

vector<long long> de(NMAX, INF);
vector<long long> ds(NMAX, INF);
vector<pair<long long, int>> d;
vector<vector<edge>> G(NMAX);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int n, m, start, goal;
  cin >> n >> m >> start >> goal;
  vector<long long> ans(n, INF);
  start--;
  goal--;
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge e1 = {v, a, b};
    edge e2 = {u, a, b};
    G[u].push_back(e1);
    G[v].push_back(e2);
  }
  // start to goal
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  pair<long long, int> p = make_pair(0, start);
  de[start] = 0;
  pq.push(p);
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second;
    if (minn > de[v])
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (de[G[v][i].to] > G[v][i].en + minn) {
        de[G[v][i].to] = G[v][i].en + minn;
        pq.emplace(de[G[v][i].to], G[v][i].to);
      }
    }
  }
  // goal to start
  p = make_pair(0, goal);
  ds[goal] = 0;
  pq.push(p);
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second;
    if (minn > ds[v])
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (ds[G[v][i].to] > G[v][i].snuuk + minn) {
        ds[G[v][i].to] = G[v][i].snuuk + minn;
        pq.emplace(ds[G[v][i].to], G[v][i].to);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    d.push_back(make_pair(de[i] + ds[i], i));
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < n; i++) {
    long long minn = d[i].first;
    long long t = d[i].second;
    for (int j = t; j >= 0; j--) {
      if (ans[j] == INF)
        ans[j] = minn;
      else
        break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (long long)1e15 - ans[i] << endl;
  }
}