Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// graph template
template <typename T> class Edge {
public:
  int src, to;
  T cost;

  Edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  Edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using AdjacencyList = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T> vector<T> dijkstra(AdjacencyList<T> &g, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(g.size(), INF);

  using Pr = pair<T, int>;
  priority_queue<Pr, vector<Pr>, greater<Pr>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);

  while (not que.empty()) {
    T cost;
    int v;
    tie(cost, v) = que.top();
    que.pop();
    if (dist[v] < cost)
      continue;

    for (auto &e : g[v]) {
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.emplace(dist[e.to], e.to);
      }
    }
  }

  return dist;
}

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

  AdjacencyList<ll> g1(n), g2(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g1[u].push_back(Edge<ll>(v, a));
    g1[v].push_back(Edge<ll>(u, a));
    g2[u].push_back(Edge<ll>(v, b));
    g2[v].push_back(Edge<ll>(u, b));
  }

  vector<ll> vec1 = dijkstra(g1, s);
  vector<ll> vec2 = dijkstra(g2, t);

  vector<ll> vec;
  for (int i = 0; i < n; i++) {
    ll mi = (ll)1e17;
    for (int j = i; j < n; j++) {
      mi = min(mi, vec1[j] + vec2[j]);
    }
    vec.push_back((ll)1e15 - mi);
  }

  for (auto res : vec)
    cout << res << '\n';

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// graph template
template <typename T> class Edge {
public:
  int src, to;
  T cost;

  Edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  Edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using AdjacencyList = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T> vector<T> dijkstra(AdjacencyList<T> &g, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(g.size(), INF);

  using Pr = pair<T, int>;
  priority_queue<Pr, vector<Pr>, greater<Pr>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);

  while (not que.empty()) {
    T cost;
    int v;
    tie(cost, v) = que.top();
    que.pop();
    if (dist[v] < cost)
      continue;

    for (auto &e : g[v]) {
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.emplace(dist[e.to], e.to);
      }
    }
  }

  return dist;
}

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

  AdjacencyList<ll> g1(n), g2(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g1[u].push_back(Edge<ll>(v, a));
    g1[v].push_back(Edge<ll>(u, a));
    g2[u].push_back(Edge<ll>(v, b));
    g2[v].push_back(Edge<ll>(u, b));
  }

  vector<ll> vec1 = dijkstra(g1, s);
  vector<ll> vec2 = dijkstra(g2, t);

  vector<ll> vec(n);
  vec[n - 1] = (ll)1e15 - vec1[n - 1] - vec2[n - 1];
  for (int i = n - 1; i >= 1; i--) {
    vec[i - 1] = max(vec[i], (ll)1e15 - vec1[i - 1] - vec2[i - 1]);
  }

  for (auto res : vec)
    cout << res << '\n';

  return 0;
}