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

#include <algorithm>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long W;

const W INF = 1LL << 50;

struct edge {
  int to;
  W cost;
};
typedef pair<W, int> P;
typedef vector<vector<edge>> Graph;

void dijkstra(int s, const Graph &G, vector<W> &d) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int toV(int n, int l) { return 101 * n + l; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, L;
  while (cin >> N >> M >> L, N) {
    Graph G(10100);
    while (M--) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      for (int l = 0; l <= L; l++) {
        if (l - d >= 0) {
          G[toV(a, l)].push_back(edge{toV(b, l - d), 0});
          G[toV(b, l)].push_back(edge{toV(a, l - d), 0});
        }
        G[toV(a, l)].push_back(edge{toV(b, l), e});
        G[toV(b, l)].push_back(edge{toV(a, l), e});
      }
    }
    vector<W> d(10100);
    dijkstra(toV(0, L), G, d);
    W ans = INF;
    for (int l = 0; l <= L; l++) {
      ans = min(ans, d[toV(N - 1, l)]);
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long W;

const W INF = 1LL << 50;

struct edge {
  int to;
  W cost;
};
typedef pair<W, int> P;
typedef vector<vector<edge>> Graph;

void dijkstra(int s, const Graph &G, vector<W> &d) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int toV(int n, int l) { return 100 * n + l; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, L;
  while (cin >> N >> M >> L, N) {
    Graph G(10000);
    while (M--) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      for (int l = 0; l <= L; l++) {
        if (l - d >= 0) {
          G[toV(a, l)].push_back(edge{toV(b, l - d), 0});
          G[toV(b, l)].push_back(edge{toV(a, l - d), 0});
        }
        G[toV(a, l)].push_back(edge{toV(b, l), e});
        G[toV(b, l)].push_back(edge{toV(a, l), e});
      }
    }
    vector<W> d(10000);
    dijkstra(toV(0, L), G, d);
    W ans = INF;
    for (int l = 0; l <= L; l++) {
      ans = min(ans, d[toV(N - 1, l)]);
    }
    cout << ans << endl;
  }
}