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

#include <bits/stdc++.h>
#define P pair<int, int>
#define int long long
#define INF LLONG_MAX / 3
using namespace std;

vector<P> rinsetu[1000000]; // cost to
int mincost[1000000];
signed main() {
  int a, b, c;
  cin >> b >> a >> c;
  a--;
  b--;
  map<int, vector<P>> n, m;
  for (int d = 0; d < c; d++) {
    int e, f;
    scanf("%lld%lld", &f, &e);
    e--;
    f--;
    n[e].push_back(P(f, d * 2));
    m[f].push_back(P(e, d * 2 + 1));
    rinsetu[d * 2].push_back(P(1, d * 2 + 1));
    rinsetu[d * 2 + 1].push_back(P(1, d * 2));
  }
  m[0].push_back(P(0, c * 2));
  n[a].push_back(P(b, c * 2 + 1));
  m[b].push_back(P(a, c * 2 + 1));
  for (auto k = n.begin(); k != n.end(); k++) {
    vector<P> r = k->second;
    if (r.size() > 1) {
      sort(r.begin(), r.end());
      for (int ttt = 1; ttt < r.size(); ttt++) {
        rinsetu[r[ttt].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt - 1].second));
        rinsetu[r[ttt - 1].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt].second));
      }
    }
  }
  for (auto k = m.begin(); k != m.end(); k++) {
    vector<P> r = k->second;
    if (r.size() > 1) {
      sort(r.begin(), r.end());
      for (int ttt = 1; ttt < r.size(); ttt++) {
        rinsetu[r[ttt].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt - 1].second));
        rinsetu[r[ttt - 1].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt].second));
      }
    }
  }
  fill(mincost, mincost + c * 2 + 2, INF);
  priority_queue<P, vector<P>, greater<P>> Q;
  mincost[c * 2] = 0;
  Q.push(P(0, c * 2));
  while (Q.size()) {
    P t = Q.top();
    Q.pop();
    if (t.first > mincost[t.second])
      continue;
    for (P i : rinsetu[t.second]) {
      if (mincost[i.second] > mincost[t.second] + i.first) {
        mincost[i.second] = mincost[t.second] + i.first;
        Q.push(P(mincost[i.second], i.second));
      }
    }
  }
  if (mincost[c * 2 + 1] == INF)
    puts("-1");
  else
    cout << mincost[c * 2 + 1] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define P pair<int, int>
#define int long long
#define INF LLONG_MAX / 15
using namespace std;

vector<P> rinsetu[250000]; // cost to
int mincost[250000];
signed main() {
  int a, b, c;
  cin >> b >> a >> c;
  a--;
  b--;
  map<int, vector<P>> n, m;
  for (int d = 0; d < c; d++) {
    int e, f;
    scanf("%lld%lld", &f, &e);
    e--;
    f--;
    n[e].push_back(P(f, d * 2));
    m[f].push_back(P(e, d * 2 + 1));
    rinsetu[d * 2].push_back(P(1, d * 2 + 1));
    rinsetu[d * 2 + 1].push_back(P(1, d * 2));
  }
  m[0].push_back(P(0, c * 2));
  n[a].push_back(P(b, c * 2 + 1));
  m[b].push_back(P(a, c * 2 + 1));
  for (auto k = n.begin(); k != n.end(); k++) {
    vector<P> r = k->second;
    if (r.size() > 1) {
      sort(r.begin(), r.end());
      for (int ttt = 1; ttt < r.size(); ttt++) {
        rinsetu[r[ttt].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt - 1].second));
        rinsetu[r[ttt - 1].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt].second));
      }
    }
  }
  for (auto k = m.begin(); k != m.end(); k++) {
    vector<P> r = k->second;
    if (r.size() > 1) {
      sort(r.begin(), r.end());
      for (int ttt = 1; ttt < r.size(); ttt++) {
        rinsetu[r[ttt].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt - 1].second));
        rinsetu[r[ttt - 1].second].push_back(
            P(r[ttt].first - r[ttt - 1].first, r[ttt].second));
      }
    }
  }
  fill(mincost, mincost + c * 2 + 2, INF);
  priority_queue<P, vector<P>, greater<P>> Q;
  mincost[c * 2] = 0;
  Q.push(P(0, c * 2));
  while (Q.size()) {
    P t = Q.top();
    Q.pop();
    if (t.first > mincost[t.second])
      continue;
    for (P i : rinsetu[t.second]) {
      if (mincost[i.second] > mincost[t.second] + i.first) {
        mincost[i.second] = mincost[t.second] + i.first;
        Q.push(P(mincost[i.second], i.second));
      }
    }
  }
  if (mincost[c * 2 + 1] == INF)
    puts("-1");
  else
    cout << mincost[c * 2 + 1] << endl;
}