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

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for (ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n)&1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int dist[110][110];
vector<int> G[110];
vector<int> D[110];
vector<int> E[110];

int main() {
  int N, M, L;
  while (cin >> N >> M >> L && N + M + L) {
    REP(i, 110) {
      G[i].clear();
      D[i].clear();
      E[i].clear();
    }

    REP(i, M) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      G[a].push_back(b);
      D[a].push_back(d);
      E[a].push_back(e);
      G[b].push_back(a);
      D[b].push_back(d);
      E[b].push_back(e);
    }
    priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>>
        que;

    fill(&dist[0][0], &dist[0][0] + 110 * 110, INF);
    dist[1][L] = 0;

    que.push(MP(0, P(1, L)));

    while (!que.empty()) {
      int c = que.top().first;
      int v = que.top().second.first;
      int l = que.top().second.second;
      que.pop();
      if (v == N) {
        cout << c << endl;
        break;
      }
      if (c > dist[v][l])
        continue;

      REP(i, G[v].size()) {
        int to = G[v][i];
        int cost = D[v][i];
        int enemy = E[v][i];
        if (cost <= l && c < dist[to][l - cost]) {
          dist[to][l - cost] = c;
          que.push(MP(c, P(to, l - cost)));
        }

        if (c + enemy < dist[to][l]) {
          dist[to][l] = c + enemy;
          que.push(MP(c + enemy, P(to, l)));
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;

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

vector<edge> G[200];
int dis[200][200];

int main() {
  int n, m, l;
  while (cin >> n >> m >> l && (n || m || l)) {
    memset(dis, -1, sizeof(dis));
    priority_queue<PP, vector<PP>, greater<PP>> que;
    for (int i = 0; i < m; i++) {
      edge e;
      int from;
      int to;
      cin >> from >> e.to >> e.cost >> e.enemy;
      G[from].push_back(e);
      to = from;
      from = e.to;
      e.to = to;
      G[from].push_back(e);
    }
    dis[1][l] = 0;
    que.push(PP(0, P(1, l)));
    while (!que.empty()) {
      PP pp = que.top();
      que.pop();
      P p = pp.second;
      if (dis[p.first][p.second] < pp.first)
        continue;
      for (int i = 0; i < G[p.first].size(); i++) {
        edge e = G[p.first][i];
        if (dis[e.to][p.second] < 0 ||
            dis[e.to][p.second] > dis[p.first][p.second] + e.enemy) {
          dis[e.to][p.second] = dis[p.first][p.second] + e.enemy;
          que.push(PP(dis[e.to][p.second], P(e.to, p.second)));
        }
        if (p.second >= e.cost) {
          if (dis[e.to][p.second - e.cost] < 0 ||
              dis[e.to - e.cost][p.second] > dis[p.first][p.second]) {
            dis[e.to][p.second - e.cost] = dis[p.first][p.second];
            que.push(
                PP(dis[e.to][p.second - e.cost], P(e.to, p.second - e.cost)));
          }
        }
      }
    }
    int min_dis = INF;
    for (int i = 0; i <= l; i++) {
      if (dis[n][i] >= 0)
        min_dis = min(min_dis, dis[n][i]);
    }
    cout << min_dis << endl;
    for (int i = 0; i < 200; i++) {
      G[i].clear();
    }
  }
  return 0;
}