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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2151

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

typedef pair<int, int> state;      // 頂点、残金
typedef pair<state, int> pass;     // 状態、悪党
typedef tuple<int, int, int> cand; // -1 * cost, point, money

vector<pass> V[110][110];

int main() {
  int N, M, L;
  while (cin >> N >> M >> L && N) {
    N--;
    // 初期化
    for (auto i = 0; i < 110; i++) {
      for (auto j = 0; j < 110; j++) {
        V[i][j].clear();
      }
    }
    // 入力受け取り
    int AA[10000], BB[10000], DD[10000], EE[10000];
    for (auto i = 0; i < M; i++) {
      cin >> AA[i] >> BB[i] >> DD[i] >> EE[i];
      AA[i]--;
      BB[i]--;
    }
    // 隣接リスト作成
    for (auto i = 0; i < M; i++) {
      for (auto j = 0; j <= L; j++) {
        V[AA[i]][j].push_back(make_pair(make_pair(BB[i], j), EE[i]));
        V[BB[i]][j].push_back(make_pair(make_pair(AA[i], j), EE[i]));
        int t = j - DD[i];
        if (t >= 0) {
          V[AA[i]][j].push_back(make_pair(make_pair(BB[i], t), 0));
          V[BB[i]][j].push_back(make_pair(make_pair(AA[i], t), 0));
        }
      }
    }
    // Dijkstra法
    priority_queue<cand> Q;
    Q.push(make_tuple(0, 0, L));
    bool visited[110][110];
    fill(&visited[0][0], &visited[0][0] + 110 * 110, false);
    int ans = 0;
    while (!Q.empty()) {
      int np = get<1>(Q.top());
      int nl = get<2>(Q.top());
      int nc = -1 * get<0>(Q.top());
      Q.pop();
      if (!visited[np][nl]) {
        visited[np][nl] = true;
        // cerr << "visiting " << np << " at " << nl << endl;
        if (np == N) {
          ans = nc;
          break;
        }
        for (auto i = 0; i < V[np][nl].size(); i++) {
          int dp = V[np][nl][i].first.first;
          int dl = V[np][nl][i].first.second;
          int dc = V[np][nl][i].second;
          if (!visited[dp][dl]) {
            Q.push(make_tuple(-1 * (dc + nc), dp, dl));
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2151

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

typedef pair<int, int> state;      // 頂点、残金
typedef pair<state, int> pass;     // 状態、悪党
typedef tuple<int, int, int> cand; // -1 * cost, point, money

vector<pass> V[110][110];

int main() {
  int N, M, L;
  while (cin >> N >> M >> L && N) {
    N--;
    // 初期化
    for (auto i = 0; i < 110; i++) {
      for (auto j = 0; j < 110; j++) {
        V[i][j].clear();
      }
    }
    // 入力受け取り
    int AA[110], BB[110], DD[110], EE[110];
    for (auto i = 0; i < M; i++) {
      cin >> AA[i] >> BB[i] >> DD[i] >> EE[i];
      AA[i]--;
      BB[i]--;
    }
    // 隣接リスト作成
    for (auto i = 0; i < M; i++) {
      for (auto j = 0; j <= L; j++) {
        V[AA[i]][j].push_back(make_pair(make_pair(BB[i], j), EE[i]));
        V[BB[i]][j].push_back(make_pair(make_pair(AA[i], j), EE[i]));
        int t = j - DD[i];
        if (t >= 0) {
          V[AA[i]][j].push_back(make_pair(make_pair(BB[i], t), 0));
          V[BB[i]][j].push_back(make_pair(make_pair(AA[i], t), 0));
        }
      }
    }
    // Dijkstra法
    priority_queue<cand> Q;
    Q.push(make_tuple(0, 0, L));
    bool visited[110][110];
    fill(&visited[0][0], &visited[0][0] + 110 * 110, false);
    int ans = 0;
    while (!Q.empty()) {
      int np = get<1>(Q.top());
      int nl = get<2>(Q.top());
      int nc = -1 * get<0>(Q.top());
      Q.pop();
      if (!visited[np][nl]) {
        visited[np][nl] = true;
        // cerr << "visiting " << np << " at " << nl << endl;
        if (np == N) {
          ans = nc;
          break;
        }
        for (auto i = 0; i < V[np][nl].size(); i++) {
          int dp = V[np][nl][i].first.first;
          int dl = V[np][nl][i].first.second;
          int dc = V[np][nl][i].second;
          if (!visited[dp][dl]) {
            Q.push(make_tuple(-1 * (dc + nc), dp, dl));
          }
        }
      }
    }
    cout << ans << endl;
  }
}