Problem p00212 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cout << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 1120000000

int main() {
  using P = pair<int, int>;
  int c, n, m, s, t;
  while (cin >> c >> n >> m >> s >> t, c | n | m) {
    s--;
    t--;
    vector<vector<P>> vec(n);
    rep(i, m) {
      int a, b, f;
      cin >> a >> b >> f;
      a--;
      b--;
      vec[a].pb(mp(f, b));
      vec[b].pb(mp(f, a));
    }

    vector<vector<int>> d(m, vector<int>(c + 1, INF));
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(mp(0, s * (c + 1)));
    d[s][c] = 0;
    while (!pq.empty()) {
      auto p = pq.top();
      pq.pop();
      int v = p.se / (c + 1);
      int k = p.se % (c + 1);
      if (d[v][k] < p.fi)
        continue;

      auto go = [&](int nv, int nk, int dist) {
        if (d[nv][nk] > dist) {
          pq.push(mp(dist, nv * (c + 1) + nk));
          d[nv][nk] = dist;
        }
      };

      for (auto to : vec[v]) {
        go(to.se, k, p.fi + to.fi);
        if (k < c)
          go(to.se, k + 1, p.fi + to.fi / 2);
      }
    }

    cout << *min_element(all(d[t])) << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cout << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 1120000000

int main() {
  using P = pair<int, int>;
  int c, n, m, s, t;
  while (cin >> c >> n >> m >> s >> t, c | n | m) {
    s--;
    t--;
    vector<vector<P>> vec(n);
    rep(i, m) {
      int a, b, f;
      cin >> a >> b >> f;
      a--;
      b--;
      vec[a].pb(mp(f, b));
      vec[b].pb(mp(f, a));
    }

    vector<vector<int>> d(n, vector<int>(c + 1, INF));
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(mp(0, s * (c + 1)));
    d[s][c] = 0;
    while (!pq.empty()) {
      auto p = pq.top();
      pq.pop();
      int v = p.se / (c + 1);
      int k = p.se % (c + 1);
      if (d[v][k] < p.fi)
        continue;

      auto go = [&](int nv, int nk, int dist) {
        if (d[nv][nk] > dist) {
          pq.push(mp(dist, nv * (c + 1) + nk));
          d[nv][nk] = dist;
        }
      };

      for (auto to : vec[v]) {
        go(to.se, k, p.fi + to.fi);
        if (k < c)
          go(to.se, k + 1, p.fi + to.fi / 2);
      }
    }

    cout << *min_element(all(d[t])) << endl;
  }

  return 0;
}