Problem p03305 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
class Town {
  std::vector<std::pair<long long int, int>> mStack{};

public:
  void addEdge(const long long int cost, const int toTown) {
    mStack.push_back(std::make_pair(cost, toTown));
  }
  const std::vector<std::pair<long long int, int>> rails() const {
    return mStack;
  }
};
std::vector<long long int> searchMinPath(const std::vector<Town> &towns,
                                         const int start) {
  auto comparator = [](const std::pair<long long int, int> a,
                       const std::pair<long long int, int> b) {
    return a.first < b.first;
  };
  auto queue = std::priority_queue<std::pair<long long int, int>,
                                   std::vector<std::pair<long long int, int>>,
                                   decltype(comparator)>(comparator);
  auto minCost = std::vector<long long int>(towns.size(), LLONG_MAX);
  minCost[start] = 0;
  queue.push(std::make_pair(minCost[start], start));
  while (queue.size() != 0) {
    auto top = queue.top();
    queue.pop();
    if (minCost[top.second] == top.first) {
      for (const auto rail : towns[top.second].rails()) {
        if (minCost[rail.second] > top.first + rail.first) {
          minCost[rail.second] = top.first + rail.first;
          queue.push(std::make_pair(minCost[rail.second], rail.second));
        }
      }
    }
  }
  return minCost;
}
int main() {
  constexpr long long int money = 1000000000000000L;
  int n, m, s, t;
  std::cin >> n >> m >> s >> t;
  auto townsYen = std::vector<Town>(n);
  auto townsSnuke = std::vector<Town>(n);
  for (auto i = 0; i < m; ++i) {
    int u, v;
    long long int a, b;
    std::cin >> u >> v >> a >> b;
    townsYen[u - 1].addEdge(a, v - 1);
    townsYen[v - 1].addEdge(a, u - 1);
    townsSnuke[u - 1].addEdge(b, v - 1);
    townsSnuke[v - 1].addEdge(b, u - 1);
  }
  auto minYenFromStart = searchMinPath(townsYen, s - 1);
  auto minSnukeFromGoal = searchMinPath(townsSnuke, t - 1);
  auto minCost = std::vector<long long int>(n);
  for (auto i = 0; i < n; ++i)
    minCost[i] = minYenFromStart[i] + minSnukeFromGoal[i];
  for (int i = n - 1; i > 0; --i)
    minCost[i - 1] = std::min(minCost[i], minCost[i - 1]);
  for (const auto min : minCost) {
    std::cout << money - min << std::endl;
  }
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
class Town {
  std::vector<std::pair<long long int, int>> mStack{};

public:
  void addEdge(const long long int cost, const int toTown) {
    mStack.push_back(std::make_pair(cost, toTown));
  }
  const std::vector<std::pair<long long int, int>> rails() const {
    return mStack;
  }
};
std::vector<long long int> searchMinPath(const std::vector<Town> &towns,
                                         const int start) {
  auto comparator = [](const std::pair<long long int, int> a,
                       const std::pair<long long int, int> b) {
    return a.first > b.first;
  };
  auto queue = std::priority_queue<std::pair<long long int, int>,
                                   std::vector<std::pair<long long int, int>>,
                                   decltype(comparator)>(comparator);
  auto minCost = std::vector<long long int>(towns.size(), LLONG_MAX);
  minCost[start] = 0;
  queue.push(std::make_pair(minCost[start], start));
  while (queue.size() != 0) {
    auto top = queue.top();
    queue.pop();
    if (minCost[top.second] == top.first) {
      for (const auto rail : towns[top.second].rails()) {
        if (minCost[rail.second] > top.first + rail.first) {
          minCost[rail.second] = top.first + rail.first;
          queue.push(std::make_pair(minCost[rail.second], rail.second));
        }
      }
    }
  }
  return minCost;
}
int main() {
  constexpr long long int money = 1000000000000000L;
  int n, m, s, t;
  std::cin >> n >> m >> s >> t;
  auto townsYen = std::vector<Town>(n);
  auto townsSnuke = std::vector<Town>(n);
  for (auto i = 0; i < m; ++i) {
    int u, v;
    long long int a, b;
    std::cin >> u >> v >> a >> b;
    townsYen[u - 1].addEdge(a, v - 1);
    townsYen[v - 1].addEdge(a, u - 1);
    townsSnuke[u - 1].addEdge(b, v - 1);
    townsSnuke[v - 1].addEdge(b, u - 1);
  }
  auto minYenFromStart = searchMinPath(townsYen, s - 1);
  auto minSnukeFromGoal = searchMinPath(townsSnuke, t - 1);
  auto minCost = std::vector<long long int>(n);
  for (auto i = 0; i < n; ++i)
    minCost[i] = minYenFromStart[i] + minSnukeFromGoal[i];
  for (int i = n - 1; i > 0; --i)
    minCost[i - 1] = std::min(minCost[i], minCost[i - 1]);
  for (const auto min : minCost) {
    std::cout << money - min << std::endl;
  }
}