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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define IREP(it, array)                                                        \\
  for (vector<int>::iterator it = array.begin(); it != array.end(); ++it)
#define PREP(it, array)                                                        \\
  for (vector<P>::iterator it = array.begin(); it != array.end(); ++it)
#define SREP(it, array)                                                        \\
  for (vector<string>::iterator it = array.begin(); it != array.end(); ++it)

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()

const int INF = 1 << 29;
const double EPS = 1e-9;
double zero(double d) { return d < EPS ? 0.0 : d; }

typedef long long LL;
typedef pair<int, int> P;

int main() {
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int N, M, K;
  cin >> N >> M >> K;

  vector<P> node[N + 1];

  int d[N + 1];
  fill(d, d + N + 1, INF);

  priority_queue<P, vector<P>, greater<P>> pque;

  REP(_t, M) {
    int a, b, l;
    cin >> a >> b >> l;
    node[a].PB(MP(b, l));
    node[b].PB(MP(a, l));
  }

  REP(_t, K) {
    int a;
    cin >> a;
    pque.push(P(0, a));
    d[a] = 0;
  }

  // dijkstra
  while (!pque.empty()) {
    P p = pque.top();
    pque.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    PREP(it, node[v]) {
      int to = (*it).first;
      int cost = (*it).second;
      if (d[to] > d[v] + cost) {
        d[to] = d[v] + cost;
        pque.push(P(cost, to));
      }
    }
  }

  int res = 0;
  REP(i, N + 1) {
    if (d[i] != INF) {
      res = max(res, d[i]);

      PREP(it, node[i]) {
        int to = (*it).first;
        int cost = (*it).second;
        if (cost != INF) {
          int val = (double)(d[i] + cost + d[to]) / 2 + 0.5;
          res = max(res, val);
        }
      }
    }
  }

  cout << res << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define IREP(it, array)                                                        \\
  for (vector<int>::iterator it = array.begin(); it != array.end(); ++it)
#define SREP(it, array)                                                        \\
  for (vector<string>::iterator it = array.begin(); it != array.end(); ++it)

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()

const int INF = 1 << 29;
const double EPS = 1e-9;
double zero(double d) { return d < EPS ? 0.0 : d; }

typedef long long LL;
typedef pair<int, int> P;

int main() {
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int N, M, K;
  cin >> N >> M >> K;

  int cost[N + 1][N + 1];
  REP(i, N + 1) {
    fill(cost[i], cost[i] + N + 1, INF);
    cost[i][i] = 0;
  }
  int d[N + 1];
  fill(d, d + N + 1, INF);

  priority_queue<P, vector<P>, greater<P>> pque;

  REP(_t, M) {
    int a, b, l;
    cin >> a >> b >> l;
    cost[a][b] = cost[b][a] = l;
  }

  REP(_t, K) {
    int a;
    cin >> a;
    pque.push(P(0, a));
    d[a] = 0;
  }

  // dijkstra
  while (!pque.empty()) {
    P p = pque.top();
    pque.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    REP(i, N + 1) {
      if (d[i] > d[v] + cost[v][i]) {
        d[i] = d[v] + cost[v][i];
        pque.push(P(d[i], i));
      }
    }
  }

  int res = 0;
  REP(i, N + 1) {
    REP(j, N + 1) {
      if (d[i] != INF) {
        res = max(res, d[i]);
        if (cost[i][j] != INF) {
          int val = (double)(d[i] + cost[i][j] + d[j]) / 2 + 0.5;
          res = max(res, val);
        }
      }
    }
  }

  cout << res << endl;

  return 0;
}