Language: C++

#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>

#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>

using namespace std;
ll n;
ll ncr(ll n, ll r)
{
    ll i, ans = 1, k = 0;
    if (r == 0)
        return 1;
    else if (n < r)
        return 0;
    for (i = n; i >= n - r + 1; i--)
    {
        ans *= i;
        ans /= n - i + 1;
    }


    return ans;

}


void max_heapify(int a[100], int i)
{
    int l, r, largest = i;
    l = 2 * i + 1;
    r = 2 * i + 2;
    if (l<n && a[l]>a[i])
        largest = l;
    if (r<n && a[r]>a[l])
        largest = r;
    if (largest != i)
    {
        int k;
        k = a[i];
        a[i] = a[largest];
        a[largest] = k;
        max_heapify(a, largest);
    }

}
int power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;


        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

bool square(ll n)
{
    double x;
    x = sqrt(n);
    if (x == floor(x))
        return true;
    else return false;
}


bool prime(ll n)
{
    ll i;
    for (i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

ll modi(ll a, ll m)
{
    return power(a, m - 2, m);

}
void kmp(string s, ll p[]) {
    int n = (int)s.length();
    p[0] = 0;
    for (int i = 1; i < n; i++) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }

}
void zfunc(string s, ll z[]) {

    ll n = (ll)s.length();
    z[0] = 0;
    for (ll i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min(r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }


}
struct pair_hash {
    size_t operator()(const pair<int, int>& p) const noexcept {
        return hash<ll>() ((((ll)p.first) << 32) | ((ll)p.second));
    }
};

bool palin(string s) {
    ll i, n;
    n = s.length();
    for (i = 0; i <= n / 2; i++) {
        if (s[i] != s[n - i - 1]) {
            return false;
        }
    }
    return true;
}
ll sum(ll n) {
    ll i;
    i = n;
    ll sum = 0;
    while (i > 0) {
        sum += i % 10;
        i = i / 10;
    }
    return sum;
}

ll nCr(ll n, ll r, ll p, ll fac[])
{

    if (r == 0)
        return 1;
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;

    return (fac[n] * modi(fac[r], p) % p *
        modi(fac[n - r], p) % p) % p;
}

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mod(string num, ll a)
{

    ll res = 0;


    for (ll i = 0; i < num.length(); i++)
        res = (res * 10 + (ll)num[i] - '0') % a;

    return res;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll parent[1000], sizer[1000];
ll findset(ll a) {
    if (a == parent[a]) {
        return a;
    }
    parent[a] = findset(parent[a]);
    return parent[a];
}

void unionset(ll a, ll b) {
    a = findset(a);
    b = findset(b);
    if (sizer[a] < sizer[b]) {
        swap(a, b);
    }
    sizer[b] += sizer[a];
    parent[b] = a;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct fenwick {
    vector<ll> bit;
    ll n;
    fenwick(ll n, vector<ll> v) {
        this->n = n;
        bit.assign(n, 0);
        for (ll it = 0; it < n; it++) {
            add(it, v[it]);
        }
    }

    ll sum(ll idx) {
        if (idx < 0)
            return 0;
        ll ret = 0;
        for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {
            ret += bit[idx];
        }
        return ret;
    }
    void add(ll idx, ll x) {
        for (; idx < n; idx = idx | (idx + 1)) {
            bit[idx] += x;
            bit[idx] = max(0LL, bit[idx]);
        }
    }
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
vector<ll> adj[100001];
ll visited[100001];

void bfs(ll start, ll arr[100001][3]) {
    queue<pair<ll, ll>> q;
    q.push({ start, 0 });
    while (!q.empty()) {
        pair<ll, ll> temp = q.front();
        q.pop();
        ll parent = temp.ff;
        for (auto u : adj[temp.ff]) {
            if (visited[u] < 600) {
                visited[u]++;
               
                arr[u][(temp.ss + 1) % 3] = min(arr[u][(temp.ss + 1) % 3], temp.ss + 1);
                arr[u][0] = min(arr[u][0], min(INF , arr[parent][2] + 1));
                arr[u][1] = min(arr[u][1], min(INF, arr[parent][0] + 1));
                arr[u][2] = min(arr[u][2], min(INF, arr[parent][1] + 1));
                q.push({ u, (temp.ss + 1) });
            }
            else {
                arr[u][(temp.ss + 1) % 3] = min(arr[u][(temp.ss + 1) % 3], temp.ss + 1);

            }
        }
    }
}
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, m;
        ll startt[100001][3];
        memset(startt, INF, sizeof(startt));
        for (i = 0; i < 100001; i++) {
            for (j = 0; j < 3; j++) {
                startt[i][j] = INF;
            }
       }
        cin >> n >> m;
        ll u, v;
        for (i = 0; i < m; i++) {
            cin >> u >> v;
            adj[u].pb(v);
        }
        ll s, t;
        cin >> s >> t;
        startt[s][0] = 0;
        
        bfs(s, startt);
        //for (i = 1; i <= n; i++) {
        ////    for (j = 0; j < 3; j++) {
        // //       cout << startt[i][j] << " ";
        //    }
        //    cout << endl;
        //}
        
        
        ll minans = INF;
        minans = startt[t][0];
        if (minans == INF) {
            cout << -1;
            return 0;
        }
        
        cout << minans / 3;
    }

    return 0;
}


Compiler output:
a.cc: In function 'void bfs(long long int, long long int (*)[3])':
a.cc:266:47: error: no matching function for call to 'min(long int, long long int)'
  266 |                 arr[u][0] = min(arr[u][0], min(INF , arr[parent][2] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:266:47: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  266 |                 arr[u][0] = min(arr[u][0], min(INF , arr[parent][2] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:266:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  266 |                 arr[u][0] = min(arr[u][0], min(INF , arr[parent][2] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:267:47: error: no matching function for call to 'min(long int, long long int)'
  267 |                 arr[u][1] = min(arr[u][1], min(INF, arr[parent][0] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:267:47: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  267 |                 arr[u][1] = min(arr[u][1], min(INF, arr[parent][0] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:267:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  267 |                 arr[u][1] = min(arr[u][1], min(INF, arr[parent][0] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:268:47: error: no matching function for call to 'min(long int, long long int)'
  268 |                 arr[u][2] = min(arr[u][2], min(INF, arr[parent][1] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:268:47: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  268 |                 arr[u][2] = min(arr[u][2], min(INF, arr[parent][1] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:268:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  268 |                 arr[u][2] = min(arr[u][2], min(INF, arr[parent][1] + 1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:24:13: warning: overflow in conversion from 'long int' to 'int' changes value from '999999999999999999' to '-1486618625' [-Woverflow]
   24 | #define INF 999999999999999999
      |             ^~~~~~~~~~~~~~~~~~
a.cc:288:24: note: in expansion of macro 'INF'
  288 |         memset(startt, INF, sizeof(startt));
      |                        ^~~