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

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
struct P {
  int to;
  int t;
  int c;
};
struct L {
  int id;
  int s;
  ll dis;
  bool operator<(const L &b) const { return b.dis < dis; }
};
ll dp[55][2600];

int main() {
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  int n, m, s;
  cin >> n >> m >> s;
  vector<vector<P>> G(n + 1);
  vector<int> C(n + 1);
  vector<int> D(n + 1);
  for (int i = 1; i <= m; ++i) {
    int from, to, time, cost;
    cin >> from >> to >> cost >> time;
    G[from].push_back({to, time, cost});
    G[to].push_back({from, time, cost});
  }
  for (int i = 1; i <= n; ++i) {
    cin >> C[i] >> D[i];
  }
  dp[1][min(2505, s)] = 0;
  priority_queue<L> que;
  que.push({1, min(2505, s), 0});
  while (!que.empty()) {
    L cur = que.top();
    que.pop();
    for (auto v : G[cur.id]) {
      int n_id = v.to;
      int n_s = cur.s - v.c;
      if (n_s >= 0) {
        // cout <<dp[n_id][n_s] << " " << dp[cur.id][cur.s] + cur.dis << endl;
        if (dp[n_id][n_s] > dp[cur.id][cur.s] + v.t) {
          dp[n_id][n_s] = dp[cur.id][cur.s] + v.t;
          que.push({n_id, n_s, dp[n_id][n_s]});
        }
      }
    }
    int need = min(2505, cur.s + C[cur.id]);
    if (dp[cur.id][need] > dp[cur.id][cur.s] + D[cur.id]) {
      dp[cur.id][need] = dp[cur.id][cur.s] + D[cur.id];
      que.push({cur.id, need, dp[cur.id][need]});
    }
  }

  for (int i = 2; i <= n; ++i) {
    ll minm = INT64_MAX;
    for (int j = 0; j <= 2505; ++j) {
      minm = min(minm, dp[i][j]);
    }
    cout << minm << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
struct P {
  int to;
  int t;
  int c;
};
struct L {
  int id;
  int s;
  int dis;
  bool operator<(const L &b) const { return b.dis < dis; }
};
int dp[55][2600];

int main() {
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  int n, m, s;
  cin >> n >> m >> s;
  vector<vector<P>> G(n + 1);
  vector<int> C(n + 1);
  vector<int> D(n + 1);
  for (int i = 1; i <= m; ++i) {
    int from, to, time, cost;
    cin >> from >> to >> cost >> time;
    G[from].push_back({to, time, cost});
    G[to].push_back({from, time, cost});
  }
  for (int i = 1; i <= n; ++i) {
    cin >> C[i] >> D[i];
  }
  dp[1][s] = 0;
  priority_queue<L> que;
  que.push({1, s, 0});
  while (!que.empty()) {
    L cur = que.top();
    que.pop();
    for (auto v : G[cur.id]) {
      int n_id = v.to;
      int n_s = cur.s - v.c;
      if (n_s >= 0) {
        // cout <<dp[n_id][n_s] << " " << dp[cur.id][cur.s] + cur.dis << endl;
        if (dp[n_id][n_s] > dp[cur.id][cur.s] + v.t) {
          dp[n_id][n_s] = dp[cur.id][cur.s] + v.t;
          que.push({n_id, n_s, dp[n_id][n_s]});
        }
      }
    }
    int need = min(2505, cur.s + C[cur.id]);
    if (dp[cur.id][need] > dp[cur.id][cur.s] + D[cur.id]) {
      dp[cur.id][need] = dp[cur.id][cur.s] + D[cur.id];
      que.push({cur.id, need, dp[cur.id][need]});
    }
  }

  for (int i = 2; i <= n; ++i) {
    int minm = INT32_MAX;
    for (int j = 0; j <= 2505; ++j) {
      minm = min(minm, dp[i][j]);
    }
    cout << minm << endl;
  }

  return 0;
}