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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> path;
typedef pair<ll, P> now;
vector<path> E[101];
P V[55];
ll dp[55][2505];
ll N, M, S;

int main() {
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    E[u - 1].push_back(path(P(a, b), v - 1));
    E[v - 1].push_back(path(P(a, b), u - 1));
  }
  for (int i = 0; i < N; i++) {
    ll C, D;
    cin >> C >> D;
    V[i] = P(C, D);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 50 * N; j++) {
      dp[i][j] = 1e16;
    }
  }

  priority_queue<now, vector<now>, greater<now>> que;
  if (N * 50 < S) {
    S = N * 50;
  }
  dp[0][S] = 0;
  que.push(now(0, P(S, 0)));
  while (!que.empty()) {
    now v = que.top();
    que.pop();
    ll time = v.first;
    ll money = v.second.first;
    ll position = v.second.second;
    if (dp[position][money] > time)
      continue;

    if (money < N * 50) {

      ll m;
      if (N * 50 < money + V[position].first) {
        m = N * 50;
      } else {
        m = money + V[position].first;
      }

      if (dp[position][money] + V[position].second < dp[position][m]) {
        dp[position][m] = dp[position][money] + V[position].second;
        que.push(now(dp[position][m], P(m, position)));
      }
    }
    for (int i = 0; i < E[position].size(); i++) {
      path p = E[position][i];
      ll umoney = p.first.first;
      ll utime = p.first.second;
      ll to = p.second;
      if (money - umoney >= 0) {
        if (dp[to][money - umoney] > dp[position][money] + utime) {
          dp[to][money - umoney] = dp[position][money] + utime;
          que.push(now(dp[to][money - umoney], P(money - umoney, to)));
        }
      }
    }
  }

  for (int i = 1; i < N; i++) {
    ll mi = dp[i][0];
    for (int j = 0; j <= N * 50; j++) {
      if (mi > dp[i][j]) {
        mi = dp[i][j];
      }
    }
    cout << mi << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> path;
typedef pair<ll, P> now;
vector<path> E[100];
P V[55];
ll dp[55][2505];
int N, M, S;

int main() {
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    E[u - 1].push_back(path(P(a, b), v - 1));
    E[v - 1].push_back(path(P(a, b), u - 1));
  }
  for (int i = 0; i < N; i++) {
    int C, D;
    cin >> C >> D;
    V[i] = P(C, D);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 50 * N; j++) {
      dp[i][j] = 10000000009;
    }
  }

  priority_queue<now, vector<now>, greater<now>> que;
  dp[0][S] = 0;
  que.push(now(0, P(S, 0)));
  while (!que.empty()) {
    now v = que.top();
    que.pop();
    ll time = v.first;
    ll money = v.second.first;
    ll position = v.second.second;
    if (dp[position][money] != time)
      continue;

    if (money + V[position].first <= (N + 1) * 50) {

      ll m;
      if (N * 50 < money + V[position].first) {
        m = N * 50;
      } else {
        m = money + V[position].first;
      }

      if (dp[position][money] + V[position].second < dp[position][m]) {
        dp[position][m] = dp[position][money] + V[position].second;
        que.push(now(dp[position][m], P(m, position)));
      }
    }
    for (int i = 0; i < E[position].size(); i++) {
      path p = E[position][i];
      ll umoney = p.first.first;
      ll utime = p.first.second;
      ll to = p.second;
      if (money - umoney >= 0) {
        if (dp[to][money - umoney] > dp[position][money] + utime) {
          dp[to][money - umoney] = dp[position][money] + utime;
          que.push(now(dp[to][money - umoney], P(money - umoney, to)));
        }
      }
    }
  }

  for (int i = 1; i < N; i++) {
    ll mi = dp[i][0];
    for (int j = 0; j <= N * 50; j++) {
      if (mi > dp[i][j]) {
        mi = dp[i][j];
      }
    }
    cout << mi << endl;
  }
}