Problem p02991 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

template <typename T> vector<T> make_vector(size_t sz) { return vector<T>(sz); }

template <typename T, typename... U> auto make_vector(size_t sz, U... tail) {
  return vector<decltype(make_vector<T>(tail...))>(sz, make_vector<T>(tail...));
}

template <typename T> void fill_vector(vector<T> &v, T init) {
  fill(v.begin(), v.end(), init);
}

template <typename T, typename U> void fill_vector(vector<U> &vec, T init) {
  for (auto &v : vec) {
    fill_vector<T>(v, init);
  }
}

int main() {
  int64_t n, m, s, t, inf = (1LL << 60);
  cin >> n >> m;
  auto ps = make_vector<pair<int64_t, int64_t>>(m);
  for (auto &p : ps) {
    cin >> p.first >> p.second;
    p.first--;
    p.second--;
  }
  cin >> s >> t;
  s--;
  t--;

  auto g = make_vector<pair<int64_t, int64_t>>(3, n, 0);
  for (auto &p : ps) {
    g[0][p.first].push_back({1, p.second});
    g[1][p.first].push_back({2, p.second});
    g[2][p.first].push_back({0, p.second});
  }

  auto dist = make_vector<int64_t>(3, n);
  fill_vector<int64_t>(dist, inf);

  priority_queue<pair<int64_t, pair<int64_t, int64_t>>,
                 vector<pair<int64_t, pair<int64_t, int64_t>>>, greater<>>
      pq;
  dist[0][s] = 0;
  pq.push({dist[0][s], {0, s}});

  while (!pq.empty()) {
    int64_t d = pq.top().first;
    int64_t i = pq.top().second.first;
    int64_t v = pq.top().second.second;
    pq.pop();

    if (dist[i][v] < d) {
      continue;
    }

    for (auto &p : g[i][v]) {
      int64_t j = p.first;
      int64_t u = p.second;

      if (dist[j][u] < dist[i][v] + 1) {
        continue;
      }

      dist[j][u] = dist[i][v] + 1;
      pq.push({dist[j][u], {j, u}});
    }
  }

  cout << ((dist[0][t] == inf) ? -1 : (dist[0][t] / 3)) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

template <typename T> vector<T> make_vector(size_t sz) { return vector<T>(sz); }

template <typename T, typename... U> auto make_vector(size_t sz, U... tail) {
  return vector<decltype(make_vector<T>(tail...))>(sz, make_vector<T>(tail...));
}

template <typename T> void fill_vector(vector<T> &v, T init) {
  fill(v.begin(), v.end(), init);
}

template <typename T, typename U> void fill_vector(vector<U> &vec, T init) {
  for (auto &v : vec) {
    fill_vector<T>(v, init);
  }
}

int main() {
  int64_t n, m, s, t, inf = (1LL << 60);
  cin >> n >> m;
  auto ps = make_vector<pair<int64_t, int64_t>>(m);
  for (auto &p : ps) {
    cin >> p.first >> p.second;
    p.first--;
    p.second--;
  }
  cin >> s >> t;
  s--;
  t--;

  auto g = make_vector<pair<int64_t, int64_t>>(3, n, 0);
  for (auto &p : ps) {
    g[0][p.first].push_back({1, p.second});
    g[1][p.first].push_back({2, p.second});
    g[2][p.first].push_back({0, p.second});
  }

  auto dist = make_vector<int64_t>(3, n);
  fill_vector<int64_t>(dist, inf);

  priority_queue<pair<int64_t, pair<int64_t, int64_t>>,
                 vector<pair<int64_t, pair<int64_t, int64_t>>>, greater<>>
      pq;
  dist[0][s] = 0;
  pq.push({dist[0][s], {0, s}});

  while (!pq.empty()) {
    int64_t d = pq.top().first;
    int64_t i = pq.top().second.first;
    int64_t v = pq.top().second.second;
    pq.pop();

    if (dist[i][v] < d) {
      continue;
    }

    for (auto &p : g[i][v]) {
      int64_t j = p.first;
      int64_t u = p.second;

      if (dist[j][u] <= dist[i][v] + 1) {
        continue;
      }

      dist[j][u] = dist[i][v] + 1;
      pq.push({dist[j][u], {j, u}});
    }
  }

  cout << ((dist[0][t] == inf) ? -1 : (dist[0][t] / 3)) << endl;

  return 0;
}