Problem p00890 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge() {}
  edge(int to, int cost) : to(to), cost(cost) {}
};

int n, m, c;
vector<vector<edge>> graph;

struct State {
  int now, cost, chg;
  State() {}
  State(int now, int cost, int chg) : now(now), cost(cost), chg(chg) {}
  bool operator<(const State &s) const { return cost > s.cost; }
};

vector<vint> mincost;

int dijkstra() {
  resz(mincost, n, vint(n, inf));
  priority_queue<State> que;
  mincost[0][0] = 0;
  que.emplace(0, 0, 0);
  while (!que.empty()) {
    State s = que.top();
    que.pop();
    int v = s.now, cost = s.cost, chg = s.chg;
    if (mincost[chg][v] < cost)
      continue;
    for (edge &e : graph[v]) {
      if (cost + e.cost < mincost[chg][e.to]) {
        mincost[chg][e.to] = cost + e.cost;
        que.emplace(e.to, mincost[chg][e.to], chg);
      }
      if (chg < n && cost < mincost[chg + 1][e.to]) {
        mincost[chg + 1][e.to] = cost;
        que.emplace(e.to, mincost[chg + 1][e.to], chg + 1);
      }
    }
  }
  rep(i, n + 1) {
    if (mincost[i][n - 1] <= c)
      return i;
  }
  return n;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while (cin >> n >> m >> c, n + m + c) {
    resz(graph, n);
    rep(i, m) {
      int f, t, cc;
      cin >> f >> t >> cc;
      --f, --t;
      graph[f].emplace_back(t, cc);
    }
    cout << dijkstra() << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge() {}
  edge(int to, int cost) : to(to), cost(cost) {}
};

int n, m, c;
vector<vector<edge>> graph;

struct State {
  int now, cost, chg;
  State() {}
  State(int now, int cost, int chg) : now(now), cost(cost), chg(chg) {}
  bool operator<(const State &s) const { return cost > s.cost; }
};

vector<vint> mincost;

int dijkstra() {
  resz(mincost, n + 1, vint(n, inf));
  priority_queue<State> que;
  mincost[0][0] = 0;
  que.emplace(0, 0, 0);
  while (!que.empty()) {
    State s = que.top();
    que.pop();
    int v = s.now, cost = s.cost, chg = s.chg;
    if (mincost[chg][v] < cost)
      continue;
    for (edge &e : graph[v]) {
      if (cost + e.cost < mincost[chg][e.to]) {
        mincost[chg][e.to] = cost + e.cost;
        que.emplace(e.to, mincost[chg][e.to], chg);
      }
      if (chg < n && cost < mincost[chg + 1][e.to]) {
        mincost[chg + 1][e.to] = cost;
        que.emplace(e.to, mincost[chg + 1][e.to], chg + 1);
      }
    }
  }
  rep(i, n + 1) {
    if (mincost[i][n - 1] <= c)
      return i;
  }
  return n;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while (cin >> n >> m >> c, n + m + c) {
    resz(graph, n);
    rep(i, m) {
      int f, t, cc;
      cin >> f >> t >> cc;
      --f, --t;
      graph[f].emplace_back(t, cc);
    }
    cout << dijkstra() << endl;
  }

  return 0;
}