alexjercan/bugnet huggingface dataset:
Problem p01269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int N, M, L;

struct edge {
  int to, distance, enemy;
};

struct P {
  int from, money, enemy;

  bool operator>(const P &p) const { return enemy > p.enemy; }
};

struct city {
  int money, enemy;
};

int main() {
  while (cin >> N >> M >> L, N | M | L) {
    vector<vector<edge>> E(N);
    int a, b, d, e;
    for (int i = 0; i < M; i++) {
      cin >> a >> b >> d >> e;
      E[a - 1].push_back({b, d, e});
      E[b - 1].push_back({a, d, e});
    }

    bool G[N + 1][L + 1];
    fill_n((bool *)G, (N + 1) * (L + 1), false);

    priority_queue<P, vector<P>, greater<P>> q;
    city arr[N];
    for (int i = 0; i < N; i++) {
      arr[i].money = 0;
      // arr[i].enemy = ;
    }
    q.push((P){0, L, 0});
    while (!q.empty()) {
      P p = q.top();
      q.pop();
      // goal
      if (p.from == N - 1) {
        cout << p.enemy << endl;
        break;
      }
      if (G[p.from][p.money])
        continue;
      G[p.from][p.money] = true;
      for (int i = 0; i < E[p.from].size(); i++) {
        edge e = E[p.from][i];
        q.push((P){e.to - 1, p.money, p.enemy + e.enemy});
        if (p.money - e.distance >= 0) {
          q.push((P){e.to - 1, p.money - e.distance, p.enemy});
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int N, M, L;

struct edge {
  int to, distance, enemy;
};

struct P {
  int from, money, enemy;

  bool operator>(const P &p) const { return enemy > p.enemy; }
};

struct city {
  int money, enemy;
};

int main() {
  while (cin >> N >> M >> L, N | M | L) {
    vector<vector<edge>> E(N);
    int a, b, d, e;
    for (int i = 0; i < M; i++) {
      cin >> a >> b >> d >> e;
      E[a - 1].push_back({b, d, e});
      E[b - 1].push_back({a, d, e});
    }

    priority_queue<P, vector<P>, greater<P>> q;
    city arr[N];
    for (int i = 0; i < N; i++) {
      arr[i].money = 0;
      // arr[i].enemy = ;
    }
    q.push((P){0, L, 0});
    while (!q.empty()) {
      P p = q.top();
      q.pop();
      // goal
      if (p.from == N - 1) {
        cout << p.enemy << endl;
        break;
      }
      for (int i = 0; i < E[p.from].size(); i++) {
        if (p.money >= arr[p.from].money) {
          arr[p.from].money = p.money;
          arr[p.from].enemy = p.enemy;
        } else if (p.enemy <= arr[p.from].enemy) {
          continue;
        }
        edge e = E[p.from][i];
        q.push((P){e.to - 1, p.money, p.enemy + e.enemy});
        if (p.money - e.distance >= 0) {
          q.push((P){e.to - 1, p.money - e.distance, p.enemy});
        }
      }
    }
  }
  return 0;
}
Problem p01269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

#define INF (1 << 20)
typedef pair<int, int> P;
typedef pair<int, P> Pi;
struct Edge {
  int to, cost, des;
};
vector<vector<Edge>> Graph;
int V, E, L;

int Dijkstra(int s, int g) {
  int min_cost[111][111];
  fill_n(*min_cost, 111 * 111, INF);
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  que.push(Pi(0, P(L, s)));
  min_cost[s][L] = 0;
  while (!que.empty()) {
    int cost = que.top().first;
    int des = que.top().second.first;
    int now = que.top().second.second;
    que.pop();
    if (now == g)
      return cost;
    if (cost > min_cost[now][des])
      continue;
    for (int i = 0; i < Graph[now].size(); i++) {
      Edge e = Graph[now][i];
      if (des >= e.des && min_cost[e.to][des - e.des] > cost) {
        min_cost[e.to][des - e.des] = cost;
        que.push(Pi(cost, P(des - e.des, e.to)));
      }
      if (min_cost[e.to][des] > cost + e.cost) {
        min_cost[e.to][des] = cost + e.cost;
        que.push(Pi(min_cost[e.to][des], P(des, e.to)));
      }
    }
  }
  return (-1);
}

int main() {
  while (cin >> V >> E >> L, (V || E || L)) {
    Graph.resize(V + 1);
    for (int i = 0; i < E; i++) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      a--;
      b--;
      Edge e;
      e.to = b;
      e.cost = d;
      e.des = c;
      Graph[a].push_back(e);
      e.to = a;
      Graph[b].push_back(e);
    }
    cout << Dijkstra(0, V - 1) << endl;
    Graph.clear();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<int, P> Pi;
struct Edge {
  int to, cost, des;
};
vector<vector<Edge>> Graph;
int V, E, L;

int Dijkstra(int s, int g) {
  int min_cost[111][111];
  fill_n(*min_cost, 111 * 111, INF);
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  que.push(Pi(0, P(L, s)));
  min_cost[s][L] = 0;
  while (!que.empty()) {
    int cost = que.top().first;
    int des = que.top().second.first;
    int now = que.top().second.second;
    que.pop();
    if (now == g)
      return cost;
    if (cost > min_cost[now][des])
      continue;
    for (int i = 0; i < Graph[now].size(); i++) {
      Edge e = Graph[now][i];
      if (des - e.des >= 0 && min_cost[e.to][des - e.des] > cost) {
        que.push(Pi(cost, P(des - e.des, e.to)));
      }
      if (min_cost[e.to][des] > cost + e.cost) {
        min_cost[e.to][des] = cost + e.cost;
        que.push(Pi(min_cost[e.to][des], P(des, e.to)));
      }
    }
  }
  return (-1);
}

int main() {
  while (cin >> V >> E >> L, V) {
    Graph.clear();
    Graph.resize(V);
    for (int i = 0; i < E; i++) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      a--;
      b--;
      Edge e;
      e.to = b;
      e.cost = d;
      e.des = c;
      Graph[a].push_back(e);
      e.to = a;
      Graph[b].push_back(e);
    }
    cout << Dijkstra(0, V - 1) << endl;
  }
}
Problem p01269 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX_N 150

int x[MAX_N][MAX_N][2];
int n, m, l, minx;
int dp[MAX_N][MAX_N];

int DP(int p, int v) {
  memset(dp, 127, sizeof(dp));
  dp[0][v] = 0;
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (x[j][k][0] < 1000000) {
          for (int l = 0; l <= v; l++) {
            if (dp[j][l] < 10000000) {
              dp[k][l] = min(dp[k][l], dp[j][l] + x[j][k][1]);
              if (l >= x[j][k][0]) {
                dp[k][l - x[j][k][0]] = min(dp[k][l - x[j][k][0]], dp[j][l]);
              }
            }
          }
        }
      }
    }
  }
  minx = 1145141919;
  for (int i = 0; i <= v; i++) {
    minx = min(minx, dp[p - 1][i]);
  }
  return minx;
}

int a, b, c, d;

int main() {
  while (true) {
    memset(x, 127, sizeof(x));
    cin >> n >> m >> l;
    if (n == 0 && m == 0 && l == 0) {
      break;
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      a--;
      b--;
      x[a][b][0] = c;
      x[a][b][1] = d;
      x[b][a][0] = c;
      x[b][a][1] = d;
    }
    cout << DP(n, l) << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX_N 150

int x[MAX_N][MAX_N][2];
int n, m, l, minx;
int dp[MAX_N][MAX_N];

int DP(int p, int v) {
  memset(dp, 127, sizeof(dp));
  dp[0][l] = 0;
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (x[j][k][0] < 1000000) {
          for (int l = 0; l <= v; l++) {
            if (dp[j][l] < 10000000) {
              dp[k][l] = min(dp[k][l], dp[j][l] + x[j][k][1]);
              if (l >= x[j][k][0]) {
                dp[j][l - x[j][k][1]] = min(dp[k][l - x[j][k][1]], dp[j][l]);
              }
            }
          }
        }
      }
    }
  }
  minx = 1145141919;
  for (int i = 0; i <= v; i++) {
    minx = min(minx, dp[p - 1][i]);
  }
  return minx;
}

int a, b, c, d;

int main() {
  while (true) {
    cin >> n >> m >> l;
    if (n == 0 && m == 0 && l == 0) {
      break;
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      a--;
      b--;
      x[a][b][0] = c;
      x[a][b][1] = d;
      x[b][a][0] = c;
      x[b][a][1] = d;
    }
    cout << DP(n, l) << endl;
  }
}
Problem p01269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

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

static const int INF = 1E8;
struct Edge {
  int A, B, D, E;
};
int N, M, L;
int A, B, D, E;
vector<Edge> g[111];
int d[111][111];
vector<int> tmp(3);

int main() {
  while (cin >> N >> M >> L, N) {
    rep(i, 111) g[i].clear();
    rep(i, M) {
      cin >> A >> B >> D >> E;
      g[A - 1].push_back((Edge){A - 1, B - 1, D, E});
      g[B - 1].push_back((Edge){B - 1, A - 1, D, E});
    }

    rep(i, 111) rep(j, 111) d[i][j] = INF;
    d[0][0] = 0;
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> que;
    tmp[0] = 0, tmp[1] = 0, tmp[2] = 0;
    que.push(tmp);
    while (!que.empty()) {
      vector<int> top = que.top();
      que.pop();
      int cnt = top[0];
      int cost = top[1];
      int h = top[2];
      // if(d[h][cost] < cnt) continue;
      rep(i, g[h].size()) {
        Edge e = g[h][i];
        tmp[2] = e.B;
        if (cost <= L && d[e.B][cost] > cnt + e.E) {
          d[e.B][cost] = cnt + e.E;
          tmp[0] = cnt + e.E;
          tmp[1] = cost;
          que.push(tmp);
        }
        if (cost + e.D <= L && d[e.B][cost + e.D] > cnt) {
          d[e.B][cost + e.D] = cnt;
          tmp[0] = cnt;
          tmp[1] = cost + e.D;
          que.push(tmp);
        }
      }
    }
    int res = INF;
    rep(i, 111) res = min(res, d[N - 1][i]);
    printf("%d\\n", res);
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

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

static const int INF = 1E8;
struct Edge {
  int A, B, D, E;
};
int N, M, L;
int A, B, D, E;
vector<Edge> g[111];
int d[111];
vector<int> tmp(3);

inline bool operator<(const Edge &v, const Edge &w) { return v.E < w.E; }

int main() {
  while (cin >> N >> M >> L, N) {
    rep(i, 111) g[i].clear();
    rep(i, M) {
      cin >> A >> B >> D >> E;
      g[A - 1].push_back((Edge){A - 1, B - 1, D, E});
      g[B - 1].push_back((Edge){B - 1, A - 1, D, E});
    }

    rep(i, 111) d[i] = INF;
    d[0] = 0;
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> que;
    tmp[0] = 0, tmp[1] = 0, tmp[2] = 0;
    que.push(tmp);
    while (!que.empty()) {
      vector<int> top = que.top();
      que.pop();
      int cnt = top[0];
      int cost = top[1];
      int h = top[2];
      // if(d[h] > cnt) continue;
      if (h == N - 1) {
        printf("%d\\n", cnt);
        break;
      }
      rep(i, g[h].size()) {
        Edge e = g[h][i];
        tmp[2] = e.B;
        if (cost <= L && d[e.B] >= cnt + e.E) {
          d[e.B] = cnt + e.E;
          tmp[0] = cnt + e.E;
          tmp[1] = cost;
          que.push(tmp);
        }
        if (cost + e.D <= L && d[e.B] >= cnt) {
          d[e.B] = cnt;
          tmp[0] = cnt;
          tmp[1] = cost + e.D;
          que.push(tmp);
        }
      }
    }
  }

  return 0;
}
Problem p01269 (C++) — buggy submission, verdict: Runtime Error

#include <queue>
#include <stdio.h>
#include <string.h>
struct S {
  int i, c, m;
  S(int i, int c, int m) : i(i), c(c), m(m) {}
  bool operator<(const S &r) const { return c > r.c; }
};
#define C(d) memset(d, X, sizeof(d))
int main() {
  int N, M, L, A, B, D, E, X = 0x7f7f7f7f;
  int d[100][100], e[100][100], x[100][101], i;
  while (scanf("%d%d%d", &N, &M, &L), N) {
    C(d), C(e), C(x);
    while (M--) {
      scanf("%d%d%d%d", &A, &B, &D, &E);
      A--, B--;
      d[A][B] = d[B][A] = D;
      e[A][B] = e[B][A] = E;
    }
    std::priority_queue<S> q;
    q.push(S(0, 0, L));
    for (;;) {
      S p(q.top());
      q.pop();
      if (x[p.i][p.m] <= p.c)
        continue;
      if (p.i == N - 1) {
        printf("%d\\n", p.c);
        break;
      }
      x[p.i][p.m] = p.c;
      for (i = 0; i < N; ++i) {
        if (d[p.i][i] == X)
          continue;
        if (d[p.i][i] <= p.m)
          q.push(S(i, p.c, p.m - d[p.i][i]));
        q.push(S(i, p.c + e[p.i][i], p.m));
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <queue>
#include <stdio.h>
#include <string.h>
struct S {
  int i, c, m;
  S(int i, int c, int m) : i(i), c(c), m(m) {}
  bool operator<(const S &r) const { return c > r.c; }
};
#define C(d) memset(d, X, sizeof(d))
int main() {
  int N, M, L, A, B, D, E, X = 0x7f7f7f7f;
  int d[100][100], e[100][100], x[100][100], i, j;
  while (scanf("%d%d%d", &N, &M, &L), N) {
    C(d), C(e), C(x);
    while (M--) {
      scanf("%d%d%d%d", &A, &B, &D, &E);
      A--, B--;
      d[A][B] = d[B][A] = D;
      e[A][B] = e[B][A] = E;
    }
    std::priority_queue<S> q;
    q.push(S(0, 0, L));
    for (;;) {
      S p(q.top());
      q.pop();
      if (x[p.i][p.m] <= p.c)
        continue;
      if (p.i == N - 1) {
        printf("%d\\n", p.c);
        break;
      }
      x[p.i][p.m] = p.c;
      for (i = 0; i < N; ++i) {
        if (d[p.i][i] == X)
          continue;
        if (d[p.i][i] <= p.m)
          q.push(S(i, p.c, p.m - d[p.i][i]));
        q.push(S(i, p.c + e[p.i][i], p.m));
      }
    }
  }
  return 0;
}
Problem p01269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>
#define INF 10e6;
using namespace std;

int cost[101][101][2]; // 0距離　1人数
int check[101][101];

int N, M, L;

struct node {
  int dis;
  int n;
  int cost;
  bool operator<(node a) const { return dis < a.dis; }
  bool operator>(node a) const { return dis > a.dis; }
};

int dijkstra(int g, int l) {
  node start;
  int ans;
  start.dis = 0, start.n = 1, start.cost = l;
  priority_queue<node, vector<node>, greater<node>> p;
  p.push(start);
  while (!p.empty()) {
    node tmp = p.top();
    p.pop();
    if (check[tmp.n][tmp.cost] <= tmp.dis)
      continue;
    else
      check[tmp.n][tmp.cost] = tmp.dis;
    if (tmp.n == g) {
      ans = tmp.dis;
      return ans;
    }
    for (int i = 1; i <= g; i++) {
      if (tmp.n == i)
        continue;
      node next;
      next.n = i;
      if (tmp.cost >= cost[tmp.n][i][0]) {
        next.cost = tmp.cost - cost[tmp.n][i][0];
        next.dis = tmp.dis;
        p.push(next);
      }
      next.cost = tmp.cost;
      next.dis = tmp.dis + cost[tmp.n][i][1];
      p.push(next);
    }
  }
}

int main(void) {
  while (cin >> N >> M >> L, N | M | L) {
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++)
        check[i][j] = cost[i][j][0] = cost[i][j][1] = INF;
    for (int i = 0; i < M; i++) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      cost[a][b][0] = cost[b][a][0] = d;
      cost[a][b][1] = cost[b][a][1] = e;
    }
    int res = dijkstra(N, L);
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
#define INF 10e6;
using namespace std;

int cost[101][101][2]; // 0距離　1人数

int N, M, L;

struct node {
  int dis;
  int n;
  int cost;
  bool operator<(node a) const { return dis < a.dis; }
  bool operator>(node a) const { return dis > a.dis; }
};

int dijkstra(int g, int l) {
  node start;
  int ans;
  start.dis = 0, start.n = 1, start.cost = l;
  priority_queue<node, vector<node>, greater<node>> p;
  p.push(start);
  while (!p.empty()) {
    node tmp = p.top();
    p.pop();
    if (tmp.n == g) {
      ans = tmp.dis;
      return ans;
    }
    for (int i = 1; i <= g; i++) {
      if (tmp.n == i)
        continue;
      node next;
      next.n = i;
      if (tmp.cost >= cost[tmp.n][i][0]) {
        next.cost = tmp.cost - cost[tmp.n][i][0];
        next.dis = tmp.dis;
        p.push(next);
      }
      next.cost = tmp.cost;
      next.dis = tmp.dis + cost[tmp.n][i][1];
      p.push(next);
    }
  }
}

int main(void) {
  while (cin >> N >> M >> L, N | M | L) {
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++)
        cost[i][j][0] = cost[i][j][1] = INF;
    for (int i = 0; i < M; i++) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      cost[a][b][0] = cost[b][a][0] = d;
      cost[a][b][1] = cost[b][a][1] = e;
    }
    int res = dijkstra(N, L);
    cout << res << endl;
  }
  return 0;
}
Problem p01269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> iP;
struct edge {
  int to, dis, enemy;
  edge() {}
  edge(int to, int dis, int enemy) : to(to), dis(dis), enemy(enemy) {}
};

int n, m, money;
int costed[128][128];
vector<vector<edge>> info(128);

void init() {
  for (int i = 0; i < 128; i++) {
    for (int j = 0; j < 128; j++)
      costed[i][j] = INF;
  }
  info.resize(0);
  info.resize(128);
}

void add_info() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  info[a].push_back(edge(b, c, d));
  info[b].push_back(edge(a, c, d));
}

int Dijkstra() {
  priority_queue<iP, vector<iP>, greater<iP>> que;
  que.push(iP(P(0, 1), money));
  costed[money][1] = 0;
  while (!que.empty()) {
    iP p = que.top();
    que.pop();
    int now = p.fr.sc, att = p.fr.fr, mo = p.sc;
    if (now == n)
      return att;
    for (int i = 0; i < info[now].size(); i++) {
      edge e = info[now][i];
      if (e.enemy + att < costed[mo][e.to]) {
        que.push(iP(P(att + e.enemy, e.to), mo));
        costed[mo][e.to] = e.enemy + att;
      }
      if (mo >= e.dis && att < costed[mo - e.dis][e.to]) {
        que.push(iP(P(att, e.to), mo - e.dis));
        costed[mo - e.dis][e.to] = att;
      }
    }
  }
}

int main() {
  while (cin >> n >> m >> money, n || m || money) {
    init();
    while (m--)
      add_info();
    cout << Dijkstra() << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> iP;
struct edge {
  int to, dis, enemy;
  edge() {}
  edge(int to, int dis, int enemy) : to(to), dis(dis), enemy(enemy) {}
};

int n, m, money;
int costed[128][128];
vector<vector<edge>> info(128);

void init() {
  for (int i = 0; i < 128; i++) {
    for (int j = 0; j < 128; j++)
      costed[i][j] = INF;
  }
  info.resize(0);
  info.resize(128);
}

void add_info() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  info[a].push_back(edge(b, c, d));
  info[b].push_back(edge(a, c, d));
}

int Dijkstra() {
  priority_queue<iP, vector<iP>, greater<iP>> que;
  que.push(iP(P(0, 1), money));
  costed[money][1] = 0;
  while (!que.empty()) {
    iP p = que.top();
    que.pop();
    int now = p.fr.sc, att = p.fr.fr, mo = p.sc;
    if (now == n)
      return att;
    for (int i = 0; i < info[now].size(); i++) {
      edge e = info[now][i];
      if (e.enemy + att < costed[mo][e.to]) {
        que.push(iP(P(att + e.enemy, e.to), mo));
        costed[mo][e.to] = e.enemy + att;
      }
      if (mo >= e.dis) {
        que.push(iP(P(att, e.to), mo - e.dis));
        costed[mo - e.dis][e.to] = att;
      }
    }
  }
}

int main() {
  while (cin >> n >> m >> money, n || m || money) {
    init();
    while (m--)
      add_info();
    cout << Dijkstra() << endl;
  }
}
Problem p01269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template <class T> void vin(vector<T> &v, int n) {
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
}

struct E {
  int to, d, e;
  E(int to, int d, int e) : to(to), d(d), e(e) {}
};

struct S {
  int a, h, m;
  S(int a, int h, int m) : a(a), h(h), m(m) {}
  bool operator>(const S &s) const { return a > s.a; }
};

int n, m, l;
int inf = 1 << 29;

int main() {
  while (cin >> n >> m >> l, n or m or l) {
    vector<vector<E>> g(n);
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--;
      b--;
      g[a].emplace_back(b, d, e);
      g[b].emplace_back(a, d, e);
    }
    vector<vector<int>> dist(n, vector<int>(l + 1, inf));
    dist[0][l] = 0;
    priority_queue<S, vector<S>, greater<S>> que;
    que.push(S(0, 0, l));
    while (que.size()) {
      S s = que.top();
      que.pop();
      int d = s.a, v = s.h, m = s.m;
      if (dist[v][m] < d)
        continue;
      for (auto tmp : g[v]) {
        int u = tmp.to;
        int ud = tmp.d;
        if (m - ud >= 0) {
          if (dist[u][m - ud] > d) {
            dist[u][m - ud] = d;
            que.push(S(dist[u][m - ud], u, m - ud));
          }
        }
        if (dist[u][m] > d + tmp.e) {
          dist[u][m] = d + tmp.e;
          que.push(S(dist[u][m], u, m));
        }
      }
    }
    int ans = inf;
    rep(i, l + 1) ans = min(ans, dist[n - 1][i]);
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template <class T> void vin(vector<T> &v, int n) {
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
}

int N, M, L;
int d[5000], e[5000];
bitset<100> visited;

int solve(int v, int p, int l, vector<pair<int, P>> g[]) {
  if (v == N - 1) {
    return 0;
  }

  int res = 1e8;
  for (auto tmp : g[v]) {
    int u = tmp.first;
    int d = tmp.second.first;
    int e = tmp.second.second;
    if (visited[u])
      continue;
    if (u == v)
      continue;
    visited[u] = true;
    res = min(res, solve(u, v, l, g) + e);
    if (e > 0 and l >= d)
      res = min(res, solve(u, v, l - d, g));
    visited[u] = false;
  }

  return res;
}

int main() {
  while (cin >> N >> M >> L and N and M and L) {
    vector<pair<int, P>> g[101];
    visited.reset();
    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}});
    }
    visited[0] = true;
    cout << solve(0, -1, L, g) << endl;
  }
  return 0;
}