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

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int graph[110][110];
int c, n, m, s, d;
int D[110][15];
const int INF = 1 << 28;

void Init() {
  for (int i = 0; i < 110; i++) {
    for (int k = 0; k < 110; k++) {
      graph[i][k] = INF;
    }
    for (int j = 0; j < 15; j++) {
      D[i][j] = INF;
    }
  }
}

void dijkstra() {
  priority_queue<PP, vector<PP>, greater<PP>> que;
  D[s][c] = 0;
  // PP( P(pos,cost), c )
  // .F.F -> pos
  // .F.S -> cost
  // .S   -> c
  que.push(PP(P(s, 0), c));
  while (!que.empty()) {
    PP p = que.top();
    que.pop();
    int v = p.F.F;
    for (int i = 1; i <= n; i++) {

      if (D[i][p.S] > graph[v][i] + p.F.S) {
        D[i][p.S] = graph[v][i] + p.F.S;
        que.push(PP(P(i, D[i][p.S]), p.S));
      }

      if (D[i][p.S - 1] > graph[v][i] / 2 + p.F.S && p.S != 0) {
        D[i][p.S - 1] = graph[v][i] / 2 + p.F.S;
        que.push(PP(P(i, D[i][p.S - 1]), p.S - 1));
      }
    }
  }
}

int main() {
  int x, y, co;
  while (true) {
    cin >> c >> n >> m >> s >> d;
    if (c + n + m + s + d == 0)
      break;
    Init();

    for (int i = 0; i < m; i++) {
      cin >> x >> y >> co;
      graph[x][y] = graph[y][x] = co;
    }

    dijkstra();
    int ans = INF;
    for (int i = 0; i <= c; i++)
      ans = min(ans, D[d][i]);
    cout << ans << endl;
  }
  return 0;
}

// Version.2

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
using namespace std;
typedef pair<int, int> P; // F -> to, S -> cost
typedef pair<P, int> PP;  // F->P(to,cost), S->discount
int c, n, m, s, d;
vector<PP> vec[1000];
int MD[1000][13];
const int INF = 1 << 29;

void dijkstra() {
  priority_queue<PP, vector<PP>, greater<PP>> que;
  rep(i, n + 1) rep(j, 13) MD[i][j] = INF;
  // syokika
  MD[s][c] = 0;
  que.push(PP(P(0, s), c)); // dis,start,discount

  while (!que.empty()) {
    PP p = que.top();
    que.pop(); // priority_queのPPと
    int v = p.F.S;

    for (int i = 0; i < vec[v].size(); i++) {
      PP po = vec[v][i]; // vectorのPPは意味が違うので注意！！！
      // if(MD[v][po.S] < po.F.S)continue;
      if (MD[po.F.F][c] > p.F.F + po.F.S) {
        MD[po.F.F][c] = p.F.F + po.F.S;
        que.push(PP(P(MD[po.F.F][c], po.F.F), c));
      }
      if (po.S > 0 && MD[po.F.F][p.S - 1] > p.F.F + po.F.S / 2) {
        MD[po.F.F][p.S - 1] = p.F.F + po.F.S / 2;
        que.push(PP(P(MD[po.F.F][p.S - 1], po.F.F), p.S - 1));
        vec[v][i].S--;
      }
    }
  }
}

int main() {
  int x, y, co;
  while (true) {
    cin >> c >> n >> m >> s >> d;
    if (c + n + m + s + d == 0)
      break;
    rep(i, 1000) vec[i].clear();
    rep(i, m) {
      cin >> x >> y >> co;
      vec[x].push_back(PP(P(y, co), c));
      vec[y].push_back(PP(P(x, co), c));
    }
    dijkstra();
    int ans = INF;
    for (int i = 0; i <= c; i++) {
      ans = min(ans, MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}