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

// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template <typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

template <typename T> inline T sq(T x) { return x * x; }

template <typename T, typename U> inline void chmax(T &x, U y) {
  x = std::max<T>(x, y);
}

template <typename T, typename U> inline void chmin(T &x, U y) {
  x = std::min<T>(x, y);
}

template <typename T> inline void sort(T &c) {
  std::sort(std::begin(c), std::end(c));
}

template <typename T> inline void reverse(T &c) {
  std::reverse(std::begin(c), std::end(c));
}

template <typename T> inline void unique(T &c) {
  std::sort(c);
  c.erase(std::unique(std::begin(c), std::end(c)));
}

// }}}

using pr = pair<int, int>;
using tp = tuple<int, int, int>;

int n, m, c;
vector<pr> g[100];
int dist[100][110];

int main() {
  while (cin >> n >> m >> c, n) {
    rep(i, n) g[i].clear();
    fill_n(*dist, 100 * 110, INF);

    rep(i, m) {
      int x, y, z;
      cin >> x >> y >> z;
      x--, y--;
      g[x].eb(y, z);
    }

    priority_queue<tp, vector<tp>, greater<tp>> pq;
    dist[0][0] = 0;
    pq.emplace(0, 0, 0);
    int res;
    while (pq.size()) {
      int v, cnt, sum;
      tie(cnt, sum, v) = pq.top();
      pq.pop();
      if (v == n - 1) {
        res = cnt;
        break;
      }
      for (auto &e : g[v]) {
        int to, cost;
        tie(to, cost) = e;
        if (dist[to][cnt] > sum + cost && sum + cost <= c) {
          dist[to][cnt] = sum + cost;
          pq.emplace(cnt, sum + cost, to);
        }
        if (dist[to][cnt + 1] > sum && cnt + 1 < 110) {
          dist[to][cnt + 1] = sum;
          pq.emplace(cnt + 1, sum, to);
        }
      }
    }

    cout << res << endl;
  }
}

Error: 0

Fixed submission:

// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template <typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

template <typename T> inline T sq(T x) { return x * x; }

template <typename T, typename U> inline void chmax(T &x, U y) {
  x = std::max<T>(x, y);
}

template <typename T, typename U> inline void chmin(T &x, U y) {
  x = std::min<T>(x, y);
}

template <typename T> inline void sort(T &c) {
  std::sort(std::begin(c), std::end(c));
}

template <typename T> inline void reverse(T &c) {
  std::reverse(std::begin(c), std::end(c));
}

template <typename T> inline void unique(T &c) {
  std::sort(c);
  c.erase(std::unique(std::begin(c), std::end(c)));
}

// }}}

using pr = pair<int, int>;
using tp = tuple<int, int, int>;

int n, m, c;
vector<pr> g[100];
int dist[100][110];

int main() {
  while (cin >> n >> m >> c, n) {
    rep(i, n) g[i].clear();
    fill_n(*dist, 100 * 110, INF);

    rep(i, m) {
      int x, y, z;
      cin >> x >> y >> z;
      x--, y--;
      g[x].eb(y, z);
    }

    priority_queue<tp, vector<tp>, greater<tp>> pq;
    dist[0][0] = 0;
    pq.emplace(0, 0, 0);
    int res;
    while (pq.size()) {
      int v, cnt, sum;
      tie(cnt, sum, v) = pq.top();
      pq.pop();
      if (v == n - 1) {
        res = cnt;
        break;
      }
      for (auto &e : g[v]) {
        int to, cost;
        tie(to, cost) = e;
        if (dist[cnt][to] > sum + cost && sum + cost <= c) {
          dist[cnt][to] = sum + cost;
          pq.emplace(cnt, sum + cost, to);
        }
        if (dist[cnt + 1][to] > sum && cnt + 1 < 110) {
          dist[cnt + 1][to] = sum;
          pq.emplace(cnt + 1, sum, to);
        }
      }
    }

    cout << res << endl;
  }
}