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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define BLACK 2LL
#define GRAY 1LL
#define WHITE 0LL
#define TEISU 1000000LL
#define INF 1145141919LL

vector<long long> x[4000];
long long n, m, a, b, c, k, G;
long long s[4000], d[4000], color[4000];
long long X[4000];
double maxn;
long long res;

priority_queue<long long, vector<long long>, greater<long long>> Q;

void dijkstra() {
  while (!Q.empty()) {
    int A = Q.top() / TEISU;
    int B = Q.top() % TEISU;
    Q.pop();
    color[B] = BLACK;

    if (d[B] < A * (-1))
      continue;

    for (int v = 0; v < x[B].size(); v++) {
      int w = x[B][v] / TEISU;

      if (color[w] == BLACK)
        continue;

      if (d[w] > d[B] + x[B][v] % TEISU) {

        d[w] = d[B] + x[B][v] % TEISU;
        Q.push(d[w] * TEISU + w);
        color[w] = GRAY;
      }
    }
  }
}

int main() {
  memset(X, 63, sizeof(X));
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    x[a].push_back(b * TEISU + c);
    x[b].push_back(a * TEISU + c);
  }
  for (int i = 0; i < k; i++) {
    cin >> a;
    s[a] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == 1) {
      Q.push(i);
      for (int v = 1; v <= n; v++) {
        color[v] = WHITE;
        d[v] = INF;
      }
      d[i] = 0;
      dijkstra();
      for (int j = 1; j <= n; j++) {
        X[j] = min(X[j], d[j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    maxn = max((long long)maxn, X[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < x[i].size(); j++) {
      if (abs(X[i] - X[x[i][j] / TEISU]) < x[i][j] % TEISU) {
        a = x[i][j] % TEISU - abs(X[i] - X[x[i][j] / TEISU]);
        maxn = max(maxn, (double)(max(X[i], X[(int)(x[i][j] / TEISU)]) +
                                  1.0 * a / 2.0));
      }
    }
  }
  res = (1.0 * maxn + 0.99999999);
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define BLACK 2
#define GRAY 1
#define WHITE 0
#define TEISU 1000000
#define INF 1145141919

vector<long long> x[4000];
long long n, m, a, b, c, k, G;
long long s[4000], d[4000], color[4000];
long long X[4000];
double maxn;
long long res;

priority_queue<int, vector<int>, greater<int>> Q;

void dijkstra() {
  while (!Q.empty()) {
    int A = Q.top() / TEISU;
    int B = Q.top() % TEISU;
    Q.pop();
    color[B] = BLACK;

    if (d[B] < A * (-1))
      continue;

    for (int v = 0; v < x[B].size(); v++) {
      int w = x[B][v] / TEISU;

      if (color[w] == BLACK)
        continue;

      if (d[w] > d[B] + x[B][v] % TEISU) {

        d[w] = d[B] + x[B][v] % TEISU;
        Q.push(d[w] * TEISU + w);
        color[w] = GRAY;
      }
    }
  }
}

int main() {
  memset(X, 63, sizeof(X));
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    x[a].push_back(b * TEISU + c);
    x[b].push_back(a * TEISU + c);
  }
  for (int i = 0; i < k; i++) {
    cin >> a;
    s[a] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == 1) {
      Q.push(i);
      for (int v = 1; v <= n; v++) {
        color[v] = WHITE;
        d[v] = INF;
      }
      d[i] = 0;
      dijkstra();
      for (int j = 1; j <= n; j++) {
        X[j] = min(X[j], d[j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    maxn = max((long long)maxn, X[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < x[i].size(); j++) {
      if (abs(X[i] - X[x[i][j] / TEISU]) < x[i][j] % TEISU) {
        a = x[i][j] % TEISU - abs(X[i] - X[x[i][j] / TEISU]);
        maxn = max(maxn, (double)(max(X[i], X[(int)(x[i][j] / TEISU)]) +
                                  1.0 * a / 2.0));
      }
    }
  }
  res = (1.0 * maxn + 0.99999999);
  cout << res << endl;
  return 0;
}