Problem p02703 (C++)

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 51;
int n, m, s, c[N], d[N];
struct edge {
  int to, a, b;
  edge(int _t, int _a, int _b) {
    to = _t;
    a = _a;
    b = _b;
  }
};
vector<edge> graph[N];

int seen[N][2501];
int ans[N];

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m >> s;
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    graph[u].emplace_back(v, a, b);
    graph[v].emplace_back(u, a, b);
  }

  for (int i = 1; i <= n; ++i) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= 2500; ++j) {
      seen[i][j] = -1000000000000000000;
    }
  }

  int ct = 0;
  priority_queue<pair<int, pair<int, int>>> pq;
  pair<int, int> st = {1, min(s, 2500LL)};
  pq.emplace(0, st);
  while (!pq.empty() && ct < n - 1) {
    auto p = pq.top();
    pq.pop();
    int cost = p.first;
    pair<int, int> cur = p.second;
    if (cost < seen[cur.first][cur.second]) {
      continue;
    }
    if (ans[cur.first] == 0 && cur.first > 1) {
      ans[cur.first] = -cost;
      ct++;
    }

    if (cur.second < 2500) {
      pair<int, int> nxt = {cur.first, min(2500LL, cur.second + c[cur.first])};
      pq.emplace(cost - d[cur.first], nxt);
    }

    for (edge e : graph[cur.first]) {
      if (cur.second >= e.a) {
        pair<int, int> nx = {e.to, cur.second - e.a};
        int nc = cost - e.b;
        if (seen[nx.first][nx.second] < nc) {
          pq.emplace(cost - e.b, nx);
          seen[nx.first][nx.second] = nc;
        }
      }
    }
  }

  for (int i = 2; i <= n; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 51;
int n, m, s, c[N], d[N];
struct edge {
  int to, a, b;
  edge(int _t, int _a, int _b) {
    to = _t;
    a = _a;
    b = _b;
  }
};
vector<edge> graph[N];

int seen[N][2501];
int ans[N];

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m >> s;
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    graph[u].emplace_back(v, a, b);
    graph[v].emplace_back(u, a, b);
  }

  for (int i = 1; i <= n; ++i) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= 2500; ++j) {
      seen[i][j] = -1000000000000000000;
    }
  }

  int ct = 0;
  priority_queue<pair<int, pair<int, int>>> pq;
  pair<int, int> st = {1, min(s, 2500LL)};
  pq.emplace(0, st);
  while (!pq.empty() && ct < n - 1) {
    auto p = pq.top();
    pq.pop();
    int cost = p.first;
    pair<int, int> cur = p.second;
    if (cost < seen[cur.first][cur.second]) {
      continue;
    }
    if (ans[cur.first] == 0 && cur.first > 1) {
      ans[cur.first] = -cost;
      ct++;
    }

    if (cur.second < 2500) {
      pair<int, int> nxt = {cur.first, min(2500LL, cur.second + c[cur.first])};
      int ncst = cost - d[cur.first];
      if (seen[nxt.first][nxt.second] < ncst) {
        pq.emplace(cost - d[cur.first], nxt);
        seen[nxt.first][nxt.second] = ncst;
      }
    }

    for (edge e : graph[cur.first]) {
      if (cur.second >= e.a) {
        pair<int, int> nx = {e.to, cur.second - e.a};
        int nc = cost - e.b;
        if (seen[nx.first][nx.second] < nc) {
          pq.emplace(cost - e.b, nx);
          seen[nx.first][nx.second] = nc;
        }
      }
    }
  }

  for (int i = 2; i <= n; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}