Problem p02991 (C++)

Buggy submission (status: Runtime Error):
// Marcin Knapik
// before you read it
// make sure it's a good idea
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef long double ld;

#define boost                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define szy first
#define gi second
#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()

template <class T> inline bool setmin(T &a, T b) {
  if (a > b)
    return a = b, 1;
  return 0;
}
template <class T> inline bool setmax(T &a, T b) {
  if (a < b)
    return a = b, 1;
  return 0;
}

template <class T> inline T fast(T a, T b, T mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> inline T russian(T a, T b, T mod) {
  ll res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> inline T sub(T a, T b, T mod) {
  return ((a - b) + mod) % mod;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container)
    os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container)
    os << u << " ";
  return os;
}
template <typename T> inline T gcd(T a, T b) {
  while (b)
    swap(a %= b, b);
  return a;
}

ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-11;

const ll T = 1 << 19;
const ll INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;
const long long N = 44 + 7;
ll n, m, k;
int s, t;
vvi G(N);

int odw[N][3];

void BFS() {
  queue<pair<int, int>> kolejka;
  odw[s][0] = 3;
  kolejka.push({s, 0});

  while (sz(kolejka)) {
    ii akt = kolejka.front();
    kolejka.pop();
    int v = akt.first;
    int val = akt.second;
    int nast = (val + 1) % 3;
    for (auto &u : G[v]) {
      // cout << v << ' ' << val << ' ' << u << ' ' << nast << endl;
      if (!odw[u][nast]) {
        odw[u][nast] = odw[v][val] + 1;
        kolejka.push({u, nast});
      }
    }
  }
}

int main() {
  boost;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    G[a].pb(b);
    // G[b].pb(a);
  }

  cin >> s >> t;
  odw[s][0] = 3;
  BFS();
  cout << odw[t][0] / 3 - 1 << '\n';

  for (int i = 1; i <= 3; i++) {
    for (int j = 0; j < 3; j++) {
      // cout << odw[i][j] << ' ';
    }
    // cout << endl;
  }
}

Fixed submission:
// Marcin Knapik
// before you read it
// make sure it's a good idea
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef long double ld;

#define boost                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define szy first
#define gi second
#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()

template <class T> inline bool setmin(T &a, T b) {
  if (a > b)
    return a = b, 1;
  return 0;
}
template <class T> inline bool setmax(T &a, T b) {
  if (a < b)
    return a = b, 1;
  return 0;
}

template <class T> inline T fast(T a, T b, T mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> inline T russian(T a, T b, T mod) {
  ll res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> inline T sub(T a, T b, T mod) {
  return ((a - b) + mod) % mod;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container)
    os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container)
    os << u << " ";
  return os;
}
template <typename T> inline T gcd(T a, T b) {
  while (b)
    swap(a %= b, b);
  return a;
}

ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-11;

const ll T = 1 << 19;
const ll INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;
const long long N = 1e6 + 7;
ll n, m, k;
int s, t;
vvi G(N);

int odw[N][3];

void BFS() {
  queue<pair<int, int>> kolejka;
  odw[s][0] = 3;
  kolejka.push({s, 0});

  while (sz(kolejka)) {
    ii akt = kolejka.front();
    kolejka.pop();
    int v = akt.first;
    int val = akt.second;
    int nast = (val + 1) % 3;
    for (auto &u : G[v]) {
      // cout << v << ' ' << val << ' ' << u << ' ' << nast << endl;
      if (!odw[u][nast]) {
        odw[u][nast] = odw[v][val] + 1;
        kolejka.push({u, nast});
      }
    }
  }
}

int main() {
  boost;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    G[a].pb(b);
    // G[b].pb(a);
  }

  cin >> s >> t;
  odw[s][0] = 3;
  BFS();
  cout << odw[t][0] / 3 - 1 << '\n';

  for (int i = 1; i <= 3; i++) {
    for (int j = 0; j < 3; j++) {
      // cout << odw[i][j] << ' ';
    }
    // cout << endl;
  }
}