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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

const int MAXN = 101, MAXL = 101, MAXE = 10000;
long long INF = MAXN * MAXE;
typedef pair<int, int> pp;
typedef pair<int, pp> ppp;
struct edge {
  int to, dist, enemy;
};

long long d[MAXN][MAXL];
int n, m, l;
int a, b, dist, e;

int main() {
  while (cin >> n >> m >> l && n) {
    memset(d, INF, sizeof(d));
    vector<edge> g[MAXN];

    REP(m) {
      cin >> a >> b >> dist >> e;
      a--;
      b--;

      g[a].push_back((edge){b, dist, e});
      g[b].push_back((edge){a, dist, e});
    }

    priority_queue<ppp, vector<ppp>, greater<ppp>> que;
    que.push(ppp(0, pp(-l, 0)));
    REP(l + 1) d[0][i] = 0;

    int ans = 0;
    while (!que.empty()) {
      ppp p = que.top();
      que.pop();
      int nowe = p.first, nowl = -p.second.first, now = p.second.second;
      // cout << "es:" << nowe << " mo:" << nowl << " now:"<< now << endl;

      if (now == n - 1) {
        ans = nowe;
        break;
      }
      /*bool f = false;
      REP(nowl + 1)if(d[now][i] < nowe) f = true;
      if(f) continue;
  */

      REP(g[now].size()) {
        edge ed = g[now][i];
        // cout <<"edge to:" << ed.to <<" dist:"<< ed.dist<<" enemy:" <<
        // ed.enemy << endl;

        if (nowl >= ed.dist && (d[ed.to][nowl - ed.dist] > d[now][nowl])) {
          // cout <<"edge to:" << ed.to <<" dist:"<< ed.dist<<" enemy:" <<
          // ed.enemy << endl;
          d[ed.to][nowl - ed.dist] = d[now][nowl];
          que.push(ppp(d[ed.to][nowl - ed.dist], pp(-nowl + ed.dist, ed.to)));
        }

        if (d[ed.to][nowl] > d[now][nowl] + ed.enemy) {
          d[ed.to][nowl] = d[now][nowl] + ed.enemy;
          que.push(ppp(d[ed.to][nowl], pp(-nowl, ed.to)));
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

const int MAXN = 120, MAXM = 5500, MAXL = 110, MAXD = 101, INF = 20000;

int n, m, l, a, b, d, e;
int enemy[MAXN][MAXN];
int dist[MAXN][MAXN];
bool used[MAXN][MAXL];

typedef pair<int, int> pp;
typedef pair<int, pp> ppp;

int main() {
  while (cin >> n >> m >> l && n) {
    memset(enemy, INF, sizeof(enemy));
    memset(dist, MAXD, sizeof(dist));
    memset(used, false, sizeof(used));
    priority_queue<ppp, vector<ppp>, greater<ppp>> que;
    que.push(ppp(0, pp(0, 1)));

    REP(m) {
      cin >> a >> b >> d >> e;
      enemy[b][a] = e;
      enemy[a][b] = e;
      dist[a][b] = d;
      dist[b][a] = d;
    }

    int ans = 0;
    while (1) {
      ppp q = que.top();
      que.pop();
      int nowenemy = q.first, cost = q.second.first, node = q.second.second;

      if (node == n) {
        ans = nowenemy;
        break;
      }
      if (used[node][cost])
        continue;

      used[node][cost] = 1;
      for (int i = 1; i <= n; i++)
        if (dist[node][i] != MAXD) {
          que.push(ppp(nowenemy + enemy[node][i], pp(nowenemy, i)));
          if (cost + dist[node][i] <= l)
            que.push(ppp(nowenemy, pp(cost + dist[node][i], i)));
        }
    }
    cout << ans << endl;
  }
  return 0;
}