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

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int inf = (1 << 31) - 1;
class road {
public:
  int to, distance;
  road(int a, int b) : to(a), distance(b) {}
};
class player {
public:
  int time;
  int k;
  int place;
  player(int a, int b, int c) : time(a), k(b), place(c) {}
};
class room {
public:
  int mk;
  int k;
  vector<road> rouka;
  room() : mk(inf) {}
};
bool operator<(const player &a, const player &b) { return a.time < b.time; }
bool operator>(const player &a, const player &b) { return a.time > b.time; }
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  room *map;
  map = new room[N + 1];
  for (int i = 1; i < N + 1; ++i) {
    cin >> map[i].k;
    --map[i].k;
  }
  int a, b, c;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    map[a].rouka.push_back(road(b, c));
    map[b].rouka.push_back(road(a, c));
  }
  priority_queue<player, vector<player>, greater<player>> que;
  que.push(player(0, 0, 1));
  while (true) {
    player dummy = que.top();
    que.pop();
    if (dummy.place == N) {
      cout << dummy.time << endl;
      break;
    }
    if (map[dummy.place].k != 0) {
      dummy.k = map[dummy.place].k * X;
    }
    if (map[dummy.place].mk <= abs(dummy.k)) {
      continue;
    } else {
      map[dummy.place].mk = abs(dummy.k);
    }
    for (vector<road>::iterator p = map[dummy.place].rouka.begin(),
                                fi = map[dummy.place].rouka.end();
         p != fi; ++p) {
      int nk = (dummy.k > 0) ? max(dummy.k - p->distance, 0)
                             : min(dummy.k + p->distance, 0);
      if (map[p->to].mk <= abs(nk))
        continue;
      if (map[p->to].k * nk >= 0) {
        que.push(player(dummy.time + p->distance, nk, p->to));
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
class road {
public:
  int to, distance;
  road(int a, int b) : to(a), distance(b) {}
};
class player {
public:
  int time;
  int k;
  int place;
  player(int a, int b, int c) : time(a), k(b), place(c) {}
};
class room {
public:
  bool used;
  int k;
  vector<road> rouka;
  room() : used(false) {}
};
bool operator<(const player &a, const player &b) { return a.time < b.time; }
bool operator>(const player &a, const player &b) { return a.time > b.time; }
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  room *map;
  map = new room[N + 1];
  for (int i = 1; i < N + 1; ++i) {
    cin >> map[i].k;
    --map[i].k;
  }
  int a, b, c;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    map[a].rouka.push_back(road(b, c));
    map[b].rouka.push_back(road(a, c));
  }
  priority_queue<player, vector<player>, greater<player>> que;
  que.push(player(0, 0, 1));
  while (true) {
    if (que.empty()) {
      cout << 0 << endl;
    }
    player dummy = que.top();
    que.pop();
    if (dummy.place == N) {
      cout << dummy.time << endl;
      break;
    }
    if (map[dummy.place].used) {
      continue;
    }
    if (dummy.k == 0) {
      map[dummy.place].used = true;
    }
    if (map[dummy.place].k != 0) {
      map[dummy.place].used = true;
      dummy.k = map[dummy.place].k * X;
    }
    for (vector<road>::iterator p = map[dummy.place].rouka.begin(),
                                fi = map[dummy.place].rouka.end();
         p != fi; ++p) {
      if (map[p->to].used)
        continue;
      int nk = (dummy.k > 0) ? max(dummy.k - p->distance, 0)
                             : min(dummy.k + p->distance, 0);
      if (map[p->to].k * nk >= 0) {
        que.push(player(dummy.time + p->distance, nk, p->to));
      }
    }
  }
  return 0;
}