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

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
long long inf = ((long long)1 << 63) - 1;
class room {
public:
  int x, y;
  long long fast;
  room() : fast(inf) {}
};
class player {
public:
  long long time;
  room *n;
  bool tate;
  player(room *a, long long c, bool d) : n(a), time(c), tate(d) {}
};
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 M, N, K;
  cin >> M >> N >> K;
  vector<vector<room *>> tate(M + 1), yoko(N + 1);
  room *map;
  map = new room[K + 1];
  for (int i = 0; i < K; ++i) {
    cin >> map[i].x >> map[i].y;
    tate[map[i].x].push_back(&map[i]);
    yoko[map[i].y].push_back(&map[i]);
  }
  map[K].x = M;
  map[K].y = N;
  tate[M].push_back(&map[K]);
  yoko[N].push_back(&map[K]);
  vector<room *>::iterator ps, pe;
  priority_queue<player, vector<player>, greater<player>> que;
  for (ps = tate[1].begin(), pe = tate[1].end(); ps != pe; ++ps) {
    que.push(player(*ps, (*ps)->y, false));
    (*ps)->fast = (*ps)->y;
  }
  while (!que.empty()) {
    player dummy = que.top();
    que.pop();
    if (dummy.n->x == M && dummy.n->y == N) {
      cout << dummy.time - 1 << endl;
      return 0;
    }
    if (dummy.time == dummy.n->fast) {
      if (dummy.tate) {
        for (ps = tate[dummy.n->x].begin(), pe = tate[dummy.n->x].end();
             ps != pe; ++ps) {
          long long nt = dummy.time + abs(dummy.n->y - (*ps)->y) + 1;
          if ((*ps)->fast > nt) {
            que.push(player(*ps, nt, false));
            (*ps)->fast = nt;
          }
        }
      } else {
        for (ps = yoko[dummy.n->y].begin(), pe = yoko[dummy.n->y].end();
             ps != pe; ++ps) {
          long long nt = dummy.time + abs(dummy.n->x - (*ps)->x) + 1;
          if ((*ps)->fast > nt) {
            que.push(player(*ps, nt, true));
            (*ps)->fast = nt;
          }
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
long long inf = ((long long)1 << 63) - 1;
class room {
public:
  int x, y;
  long long fast;
  room() : fast(inf) {}
};
class player {
public:
  long long time;
  room *n;
  bool tate;
  player(room *a, long long c, bool d) : n(a), time(c), tate(d) {}
};
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 M, N, K;
  cin >> M >> N >> K;
  vector<vector<room *>> tate(M + 1), yoko(N + 1);
  room *map;
  map = new room[K + 1];
  for (int i = 0; i < K; ++i) {
    cin >> map[i].x >> map[i].y;
    tate[map[i].x].push_back(&map[i]);
    yoko[map[i].y].push_back(&map[i]);
  }
  map[K].x = M;
  map[K].y = N;
  tate[M].push_back(&map[K]);
  yoko[N].push_back(&map[K]);
  vector<room *>::iterator ps, pe;
  priority_queue<player, vector<player>, greater<player>> que;
  for (ps = tate[1].begin(), pe = tate[1].end(); ps != pe; ++ps) {
    que.push(player(*ps, (*ps)->y, false));
    (*ps)->fast = (*ps)->y;
  }
  while (!que.empty()) {
    player dummy = que.top();
    que.pop();
    if (dummy.n->x == M && dummy.n->y == N) {
      cout << dummy.time - 1 << endl;
      return 0;
    }
    if (dummy.time > dummy.n->fast)
      continue;
    if (dummy.tate) {
      for (ps = tate[dummy.n->x].begin(), pe = tate[dummy.n->x].end(); ps != pe;
           ++ps) {
        long long nt = dummy.time + abs(dummy.n->y - (*ps)->y) + 1;
        if ((*ps)->fast > nt) {
          que.push(player(*ps, nt, false));
          dummy.n->fast = nt;
        }
      }
    } else {
      for (ps = yoko[dummy.n->y].begin(), pe = yoko[dummy.n->y].end(); ps != pe;
           ++ps) {
        long long nt = dummy.time + abs(dummy.n->x - (*ps)->x) + 1;
        if ((*ps)->fast > nt) {
          que.push(player(*ps, nt, true));
          dummy.n->fast = nt;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}