Problem p02703 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, m, s, ans, C[55], D[55];
long long dis[55][2505];
bool vis[55][2505];
vector<pair<int, pair<int, int>>> mp[55];
priority_queue<pair<long long, pair<int, int>>,
               vector<pair<long long, pair<int, int>>>,
               greater<pair<long long, pair<int, int>>>>
    q;
int main() {
  scanf("%d %d %d", &n, &m, &s);
  s = min(s, 2500);
  while (m--) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    mp[u].push_back({v, {a, b}});
    mp[v].push_back({u, {a, b}});
  }
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &C[i], &D[i]);
  for (int i = 1; i <= n; i++)
    for (int i0 = 0; i0 <= 2500; i0++)
      dis[i][i0] = INT64_MAX;
  dis[1][s] = 0;
  q.push({0, {1, s}});
  while (q.size()) {
    auto t = q.top();
    q.pop();
    int now = t.second.first, s = t.second.second;
    long long d = t.first;
    if (vis[now][s])
      continue;
    vis[now][s] = 1;
    if (dis[now][min(2500, s + C[now])] > d + D[now]) {
      dis[now][min(2500, s + C[now])] = d + D[now];
      q.push({dis[now][min(2500, s + C[now])], {now, min(2500, s + C[now])}});
    }
    for (auto x : mp[now]) {
      if (s >= x.second.first &&
          dis[x.first][s - x.second.first] > d + x.second.second) {
        dis[x.first][s - x.second.first] = d + x.second.second;
        q.push(
            {dis[x.first][s - x.second.first], {x.first, s - x.second.first}});
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    long long ans = INT64_MAX;
    for (int i0 = 0; i0 <= 2500; i0++)
      ans = min(ans, dis[i][i0]);
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, s, ans, C[55], D[55];
long long dis[55][2505];
bool vis[55][2505];
vector<pair<int, pair<int, int>>> mp[55];
priority_queue<pair<long long, pair<int, int>>,
               vector<pair<long long, pair<int, int>>>,
               greater<pair<long long, pair<int, int>>>>
    q;
int main() {
  scanf("%d %d %d", &n, &m, &s);
  while (m--) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    mp[u].push_back({v, {a, b}});
    mp[v].push_back({u, {a, b}});
  }
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &C[i], &D[i]);
  for (int i = 1; i <= n; i++)
    for (int i0 = 0; i0 <= 2500; i0++)
      dis[i][i0] = INT64_MAX;
  dis[1][s] = 0;
  q.push({0, {1, s}});
  while (q.size()) {
    auto t = q.top();
    q.pop();
    int now = t.second.first, s = t.second.second;
    long long d = t.first;
    if (vis[now][s])
      continue;
    vis[now][s] = 1;
    if (s < 2500) {
      if (dis[now][min(2500, s + C[now])] > d + D[now]) {
        dis[now][min(2500, s + C[now])] = d + D[now];
        q.push({dis[now][min(2500, s + C[now])], {now, min(2500, s + C[now])}});
      }
    }
    for (auto x : mp[now]) {
      if (s >= x.second.first &&
          dis[x.first][s - x.second.first] > d + x.second.second) {
        dis[x.first][s - x.second.first] = d + x.second.second;
        q.push(
            {dis[x.first][s - x.second.first], {x.first, s - x.second.first}});
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    long long ans = INT64_MAX;
    for (int i0 = 0; i0 <= 2500; i0++)
      ans = min(ans, dis[i][i0]);
    printf("%lld\\n", ans);
  }
  return 0;
}