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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
template <class T, class S> inline pair<T, S> mp(const T x, const S y) {
  return make_pair(x, y);
}
template <class T, class S> inline bool minup(T &m, const S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, const S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

static const int INF = 1000000000;
static const ll MOD = 1000000007LL;
static const double EPS = 1E-10;

const int MAX_N = 111;
const int MAX_C = 22;
int c, n, m, s, d;
int t, u, f;
struct Edge {
  int from, to, cost;
};
vector<Edge> g[MAX_N];
int l[MAX_N][MAX_C];

int main() {
  while (cin >> c >> n >> m >> s >> d, c) {
    rep(i, n) g[i].clear();
    rep(i, MAX_N) rep(j, MAX_C) l[i][j] = INF;

    rep(i, m) {
      cin >> t >> u >> f;
      g[t - 1].pb((Edge){t - 1, u - 1, f});
      g[u - 1].pb((Edge){u - 1, t - 1, f});
    }

    priority_queue<vi, vector<vi>, greater<vi>> que;
    vi tmp(3);
    tmp[0] = 0;     // ?????¢
    tmp[1] = -c;    // ?????°
    tmp[2] = s - 1; // ??´???
    l[s - 1][c] = 0;
    que.push(tmp);
    while (!que.empty()) {
      vi p = que.top();
      que.pop();
      int ti = -p[1];
      int v = p[2];
      if (l[v][ti] < p[0])
        continue;

      vrep(w, g[v]) {
        Edge &e = *w;
        if (l[e.to][ti] > l[v][ti] + e.cost) {
          l[e.to][ti] = l[v][ti] + e.cost;
          tmp[0] = l[e.to][ti];
          tmp[1] = -ti;
          tmp[2] = e.to;
          que.push(tmp);
        }
      }

      if (ti > 0)
        vrep(w, g[v]) {
          Edge &e = *w;
          if (l[e.to][ti - 1] > l[v][ti] + e.cost / 2) {
            l[e.to][ti - 1] = l[v][ti] + e.cost / 2;
            tmp[0] = l[e.to][ti - 1];
            tmp[1] = -(ti - 1);
            tmp[2] = e.to;
            que.push(tmp);
          }
        }
    }

    int res = INF;
    rep(i, c + 1) minup(res, l[d - 1][i]);
    cout << res << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
template <class T, class S> inline pair<T, S> mp(const T x, const S y) {
  return make_pair(x, y);
}
template <class T, class S> inline bool minup(T &m, const S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, const S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

static const int INF = 1000000000;
static const ll MOD = 1000000007LL;
static const double EPS = 1E-10;

const int MAX_N = 111;
const int MAX_C = 22;
int c, n, m, s, d;
int t, u, f;
struct Edge {
  int from, to, cost;
};
vector<Edge> g[MAX_N];
int l[MAX_N][MAX_C];

int main() {
  while (cin >> c >> n >> m >> s >> d, c) {
    rep(i, n) g[i].clear();
    rep(i, MAX_N) rep(j, MAX_C) l[i][j] = INF;

    rep(i, m) {
      cin >> t >> u >> f;
      g[t - 1].pb((Edge){t - 1, u - 1, f});
      g[u - 1].pb((Edge){u - 1, t - 1, f});
    }

    priority_queue<vi, vector<vi>, greater<vi>> que;
    vi tmp(3);
    tmp[0] = 0;     // ?????¢
    tmp[1] = c;     // ?????°
    tmp[2] = s - 1; // ??´???
    l[s - 1][c] = 0;
    que.push(tmp);
    while (!que.empty()) {
      vi p = que.top();
      que.pop();
      int ti = p[1];
      int v = p[2];
      if (l[v][ti] < p[0])
        continue;

      vrep(w, g[v]) {
        Edge &e = *w;
        if (l[e.to][ti] > l[v][ti] + e.cost) {
          l[e.to][ti] = l[v][ti] + e.cost;
          tmp[0] = l[e.to][ti];
          tmp[1] = ti;
          tmp[2] = e.to;
          que.push(tmp);
        }
      }

      if (c > 0)
        vrep(w, g[v]) {
          Edge &e = *w;
          if (l[e.to][ti - 1] > l[v][ti] + e.cost / 2) {
            l[e.to][ti - 1] = l[v][ti] + e.cost / 2;
            tmp[0] = l[e.to][ti - 1];
            tmp[1] = ti - 1;
            tmp[2] = e.to;
            que.push(tmp);
          }
        }
    }

    cout << l[d - 1][0] << endl;
  }

  return 0;
}