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

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

struct edge {
  int to;
  int cost;
  int numOfTheaf;
};

struct info {
  int now;
  int sumOfCost;
  int sumOfTheaf;
  bool operator<(const info &o) const { return sumOfTheaf > o.sumOfTheaf; }
};

int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<vector<edge>> G(n);
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--;
      b--;
      G[a].push_back({b, d, e});
      G[b].push_back({a, d, e});
    }
    //       to, sumOfCost -> sumOfTheaf
    int dist[110][110] = {};
    rep(i, 110) rep(j, 110) dist[i][j] = 1e9;
    bool used[110][110] = {};

    // info -> now, sumOfCost, sumOfTheaf
    priority_queue<info> que;
    que.push({0, 0, 0});

    dist[0][0] = 0;

    while (!que.empty()) {
      info tmp = que.top();
      que.pop();
      if (used[tmp.now][tmp.sumOfCost])
        continue;
      used[tmp.now][tmp.sumOfCost] = true;
      rep(i, G[tmp.now].size()) {
        // 護衛を雇わない場合
        {
          if (dist[G[tmp.now][i].to][tmp.sumOfCost] >
              dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf) {
            dist[G[tmp.now][i].to][tmp.sumOfCost] =
                dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf;
            que.push({G[tmp.now][i].to, tmp.sumOfCost,
                      dist[G[tmp.now][i].to][tmp.sumOfCost]});
          }
        }
        // 護衛を雇う場合
        {
          // お金こえちゃだめ
          if (G[tmp.now][i].cost + tmp.sumOfCost > l)
            continue;
          if (dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] >
              dist[tmp.now][tmp.sumOfCost]) {
            dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] =
                dist[tmp.now][tmp.sumOfCost];
            que.push({G[tmp.now][i].to, tmp.sumOfCost + G[tmp.now][i].cost,
                      tmp.sumOfTheaf});
          }
        }
      }
    }
    int ans = 1e9;
    rep(i, l + 1) ans = min(ans, dist[n - 1][i]);
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

struct edge {
  int to;
  int cost;
  int numOfTheaf;
};

struct info {
  int now;
  int sumOfCost;
  int sumOfTheaf;
  bool operator<(const info &o) const { return sumOfTheaf > o.sumOfTheaf; }
};

int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<vector<edge>> G(n);
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--;
      b--;
      G[a].push_back({b, d, e});
      G[b].push_back({a, d, e});
    }
    //       to, sumOfCost -> sumOfTheaf
    int dist[110][110] = {};
    rep(i, 110) rep(j, 110) dist[i][j] = 1e9;
    bool used[110][110][110] = {};
    // bool used[110][110] = {};

    // info -> now, sumOfCost, sumOfTheaf
    priority_queue<info> que;
    que.push({0, 0, 0});

    dist[0][0] = 0;

    while (!que.empty()) {
      info tmp = que.top();
      que.pop();
      // cout << tmp.now << endl;
      if (used[tmp.now][tmp.sumOfCost][tmp.sumOfTheaf])
        continue;
      used[tmp.now][tmp.sumOfCost][tmp.sumOfTheaf] = true;
      rep(i, G[tmp.now].size()) {
        // 護衛を雇わない場合
        {
          if (dist[G[tmp.now][i].to][tmp.sumOfCost] >
              dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf) {
            dist[G[tmp.now][i].to][tmp.sumOfCost] =
                dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf;
            que.push({G[tmp.now][i].to, tmp.sumOfCost,
                      dist[G[tmp.now][i].to][tmp.sumOfCost]});
          }
        }
        // 護衛を雇う場合
        {
          // お金こえちゃだめ
          if (G[tmp.now][i].cost + tmp.sumOfCost > l)
            continue;
          if (dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] >
              dist[tmp.now][tmp.sumOfCost]) {
            dist[G[tmp.now][i].to][tmp.sumOfCost] =
                dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf;
            dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] =
                dist[tmp.now][tmp.sumOfCost];
            que.push({G[tmp.now][i].to, tmp.sumOfCost + G[tmp.now][i].cost,
                      tmp.sumOfTheaf});
          }
        }
      }
    }
    int ans = 1e9;
    rep(i, l + 1) ans = min(ans, dist[n - 1][i]);
    cout << ans << endl;
  }
  return 0;
}