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

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int INF = 1e9;

// dp[i][j][k]
// :=???(?????????????????????i(mod2)??§A???????????????j????????§?¬???????k??????????????????????????????
//?????????????????????????§???°???????°??????????) (k==0:A k==1:B)
int dp[2][5010][2];
int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n - 1) cin >> v[i];
  rep(i, 2) rep(j, 5010) rep(k, 2) dp[i][j][k] = INF;

  dp[0][0][0] = 0;
  dp[0][0][1] = 0;
  //??????dp
  for (int i = 0; i < n; ++i) {
    rep(j, 5010) rep(k, 2) dp[(i + 1) % 2][j][k] =
        INF; // dp???????????¨????????????
    for (int j = 0; j <= n / 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (dp[i % 2][j][k] == INF)
          continue;
        //???????????????????????????
        if (k == 0) {
          dp[(i + 1) % 2][j + 1][k] =
              min(dp[(i + 1) % 2][j + 1][k], dp[i % 2][j][k]);
        } else {
          dp[(i + 1) % 2][j][k] = min(dp[(i + 1) % 2][j][k], dp[i % 2][j][k]);
        }
        //?????????????????????
        if (k == 0) {
          dp[(i + 1) % 2][j + 1][1] =
              min(dp[(i + 1) % 2][j + 1][1], dp[i % 2][j][k] + v[i]);
        } else {
          dp[(i + 1) % 2][j][0] =
              min(dp[(i + 1) % 2][j][0], dp[i % 2][j][k] + v[i]);
        }
      }
    }
  }

  int ans = INF;
  rep(k, 2) { ans = min(ans, dp[n % 2][n / 2][k]); }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

const int INF = 1e9;
const int MAX_N = 3010, MAX_E = 10000;
int n, m; //????????° ???????????¬??°
vector<pair<int, int>>
    G[MAX_N];             //??°???????????¨?????£??\\????????? fi:to se:cost
int d[MAX_N];             // s?????????????????????
typedef pair<int, int> P; // first??????????????¢,second??????????????????
int k;
vector<int> shop; //???????¨????

void dijkstra(void) {
  priority_queue<P, vector<P>, greater<P>> que; // first????°?????????????
  rep(i, n) d[i] = INF;                         //?????????

  // k????????????????????°????????????
  for (auto i : shop) {
    d[i] = 0;
    que.push(make_pair(0, i));
  }

  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : G[v]) { // e.fi:??£??\\???????????????????????????
                          // e.se:?????????????????§????????????
      if (d[e.first] > d[v] + e.second) { //???????????¢?????´??°???????????¨???
        d[e.first] = d[v] + e.second;
        que.push(make_pair(d[e.first], e.first));
      }
    }
  }
}

int main(void) {
  cin >> n >> m >> k;
  rep(i, m) {
    int a, b, l;
    cin >> a >> b >> l;
    a--;
    b--;
    G[a].push_back(make_pair(b, l));
    G[b].push_back(make_pair(a, l));
  }
  rep(i, k) {
    int s;
    cin >> s;
    s--;
    shop.push_back(s);
  }
  dijkstra(); //????????????????????????????°?????????????
  //?????????????????¶????????????????°?????????????
  double ans = 0.0;
  //??????????????????????????¢????????¨???????????????????????¶???????????´?????????????????????????????¢?????????
  // rep(i, n) printf("%d\\n", d[i]);
  for (int x = 0; x < n; ++x) {
    for (auto y : G[x]) {
      if (d[x] == 0 || d[y.first] == 0)
        continue;
      double tmp = (d[x] + d[y.first] + y.second) / 2.0; //+1????????¨?????\\??¨
      ans = max(tmp, ans);
    }
  }
  cout << round(ans) << endl;
  return 0;
}