Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

vector<ll> dijkstra(int n, int start, vector<vector<pair<int, ll>>> &adj) {
  vector<ll> dist(n, INF);
  dist[start] = 0;
  priority_queue<pair<ll, int>> q;
  q.push({-dist[start], start});
  while (!q.empty()) {
    int node = q.top().ss;
    q.pop();
    for (ii i : adj[node]) {
      if (dist[node] + i.ss <= dist[i.ff]) {
        dist[i.ff] = dist[node] + i.ss;
        q.push({-dist[i.ff], i.ff});
      }
    }
  }

  return dist;
}

void solve() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;

  vector<vector<pair<int, ll>>> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    ll wa, wb;
    cin >> u >> v >> wa >> wb;
    u--;
    v--;

    a[u].pub({v, wa});
    b[u].pub({v, wb});
    a[v].pub({u, wa});
    b[v].pub({u, wb});
  }

  ll mn = INF;
  vector<ll> ans(n), dists = dijkstra(n, s, a), distt = dijkstra(n, t, b);
  for (int i = n - 1; i >= 0; i--) {
    mn = min(mn, dists[i] + distt[i]);
    //		cout << dists[i] << " " << distt[i] << endl;
    ans[i] = mn;
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

vector<ll> dijkstra(int n, int start, vector<vector<pair<int, ll>>> &adj) {
  vector<ll> dist(n, INF);
  dist[start] = 0;
  priority_queue<pair<ll, int>> q;
  q.push({-dist[start], start});
  while (!q.empty()) {
    int node = q.top().ss;
    q.pop();
    for (ii i : adj[node]) {
      if (dist[node] + i.ss < dist[i.ff]) {
        dist[i.ff] = dist[node] + i.ss;
        q.push({-dist[i.ff], i.ff});
      }
    }
  }

  return dist;
}

void solve() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;

  vector<vector<pair<int, ll>>> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    ll wa, wb;
    cin >> u >> v >> wa >> wb;
    u--;
    v--;

    a[u].pub({v, wa});
    b[u].pub({v, wb});
    a[v].pub({u, wa});
    b[v].pub({u, wb});
  }

  ll mn = INF;
  vector<ll> ans(n), dists = dijkstra(n, s, a), distt = dijkstra(n, t, b);
  for (int i = n - 1; i >= 0; i--) {
    mn = min(mn, dists[i] + distt[i]);
    //		cout << dists[i] << " " << distt[i] << endl;
    ans[i] = mn;
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}