Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using  namespace std;

const int MAX = 1e5;
vector<int> to[MAX];
bool visit[MAX][4];
int N, M;
int S, T;

void dfs(queue<int> &que, int tmp, int depth) {
  if (depth == 3) {
    que.push(tmp);
    return;
  }
  for (int next : to[tmp]) {
    if (!visit[next][depth+1]) {
      visit[next][depth+1] = true;
      dfs(que, next, depth + 1);
    }
  }
}

void solve() {
  queue<int> que;
  que.push(S);
  visit[S] = true;
  int ans = 0;
  while (++ans) {
    queue<int> buf;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      dfs(buf, u, 0);
    }
    if (buf.empty()) {
      ans = -1;
      break;
    }
    if (visit[T]) break;
    swap(que, buf);
  }
  cout << ans << endl;
}

int main() {
  cin >> N >> M;
  rep(i, M) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    to[u].push_back(v);
  }
  cin >> S >> T;
  --S; --T;
  solve();
  return 0;
}

Compiler output:
a.cc: In function 'void dfs(std::queue<int>&, int, int)':
a.cc:17:10: error: reference to 'visit' is ambiguous
   17 |     if (!visit[next][depth+1]) {
      |          ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:7:6: note:                 'bool visit [100000][4]'
    7 | bool visit[MAX][4];
      |      ^~~~~
a.cc:18:7: error: reference to 'visit' is ambiguous
   18 |       visit[next][depth+1] = true;
      |       ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:7:6: note:                 'bool visit [100000][4]'
    7 | bool visit[MAX][4];
      |      ^~~~~
a.cc: In function 'void solve()':
a.cc:27:3: error: reference to 'visit' is ambiguous
   27 |   visit[S] = true;
      |   ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:7:6: note:                 'bool visit [100000][4]'
    7 | bool visit[MAX][4];
      |      ^~~~~
a.cc:40:9: error: reference to 'visit' is ambiguous
   40 |     if (visit[T]) break;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:7:6: note:                 'bool visit [100000][4]'
    7 | bool visit[MAX][4];
      |      ^~~~~