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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;

int dp[105][105];

int main(void) {
  int i, j;
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<vector<pip>> v(n);
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      v[a].push_back(pip(b, pii(d, e))); // to,cost,num
      v[b].push_back(pip(a, pii(d, e)));
    }
    priority_queue<pip, vector<pip>, greater<pip>> q;

    rep(i, 105) rep(j, 105) dp[i][j] = INF;
    dp[0][0] = 0;
    q.push(pip(0, pii(0, 0))); // num,v,cost
    while (q.size()) {

      int now_v = q.top().second.first;
      int now_cost = q.top().second.second;
      int now_num = q.top().first;
      q.pop();

      if (dp[now_v][now_cost] < now_num)
        continue;

      rep(i, v[now_v].size()) {
        int next_v = v[now_v][i].first;

        // 護衛するときは、お金がかかるが襲われる人数は増えない
        int next_cost1 = now_cost + v[now_v][i].second.first;
        int next_num1 = now_num;

        if (next_cost1 <= l && dp[next_v][next_cost1] > next_num1) {
          dp[next_v][next_cost1] = next_num1;
          q.push(pip(next_num1, pii(next_v, next_cost1)));
        }

        // 護衛しないときは、お金はかからないが襲われる人数が増える
        int next_cost2 = now_cost;
        int next_num2 = now_num + v[now_v][i].second.second;

        if (next_cost2 <= l && dp[next_v][next_cost2] > next_num2) {
          dp[next_v][next_cost2] = next_num2;
          q.push(pip(next_num2, pii(next_v, next_cost2)));
        }
      }
    }
    int ans = INF;
    rep(i, l + 1) { ans = min(ans, dp[n - 1][i]); }
    cout << ans << endl;
  }
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;

int dp[105][105];

int main(void) {
  int i, j;
  int n, m, l;
  while (cin >> n >> m >> l) {
    vector<vector<pip>> v(n);
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      v[a].push_back(pip(b, pii(d, e))); // to,cost,num
      v[b].push_back(pip(a, pii(d, e)));
    }
    priority_queue<pip, vector<pip>, greater<pip>> q;

    rep(i, 100) rep(j, 105) dp[i][j] = INF;
    dp[0][0] = 0;
    q.push(pip(0, pii(0, 0))); // num,v,cost
    while (q.size()) {

      int now_v = q.top().second.first;
      int now_cost = q.top().second.second;
      int now_num = q.top().first;
      q.pop();

      if (dp[now_v][now_cost] < now_num)
        continue;

      rep(i, v[now_v].size()) {
        int next_v = v[now_v][i].first;

        // 護衛するときは、お金がかかるが襲われる人数は増えない
        int next_cost1 = now_cost + v[now_v][i].second.first;
        int next_num1 = now_num;

        if (next_cost1 <= l && dp[next_v][next_cost1] > next_num1) {
          dp[next_v][next_cost1] = next_num1;
          q.push(pip(next_num1, pii(next_v, next_cost1)));
        }

        // 護衛しないときは、お金はかからないが襲われる人数が増える
        int next_cost2 = now_cost;
        int next_num2 = now_num + v[now_v][i].second.second;

        if (next_cost2 <= l && dp[next_v][next_cost2] > next_num2) {
          dp[next_v][next_cost2] = next_num2;
          q.push(pip(next_num2, pii(next_v, next_cost2)));
        }
      }
    }
    int ans = INF;
    rep(i, l + 1) { ans = min(ans, dp[n - 1][i]); }
    cout << ans << endl;
  }
}