stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int,int> pp;

const int INF = 1e9;

const int MOD = 1000000007;

#define rep(i,n) for(int i=0;i<n;i++)

const int MAX = 100005;

vector<vector<pp>> graph(3*MAX,vector<pp>(0));

int n = MAX,s,t;



ll dijkstra(ll goal){

  priority_queue<pp,vector<pp>,greater<pp>> pq;

  pq.push(make_pair(0,s));

  vector<int> visited(3*n,0);

  while (!pq.empty()){

    auto now = pq.top();

    pq.pop();

    ll cost,node;

    tie(cost,node) = now;

    if(node == goal){

      return cost/3 ;

    }

    if(visited.at(node)==1){

      continue;

    }else{

      visited.at(node) = 1;

      for(auto next:graph.at(node)){

        ll next_cost,next_node;

        tie(next_cost,next_node) = next;

        pq.push(make_pair(cost+next_cost,next_node));

      }

    }

  }

  return -1;

} 

int main() {

  int n,m ;

  cin >> n >> m;

  rep(i,m){

    int v,u;

    cin >> v >> u;

    --v; --u;

    graph.at(v).push_back(make_pair(1,u+n));

    graph.at(v+n).push_back(make_pair(1,u+2*n));

    graph.at(v+2*n).push_back(make_pair(1,u));

  }

  cin >> s >> t;

  --s; --t;

  

  ll ans = dijkstra(t);

  if(ans == -1) cout << -1 << endl;

  else cout << ans << endl;

}

  

  

 

// Faster C++ solution for the same problem (measured speedup: 3.0749272689194695x):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

using ll = long long ;

using P = pair<int,int> ;

using pll = pair<long long,long long>;

constexpr int INF = 1e9;

constexpr long long LINF = 1e17;

constexpr int MOD = 1000000007;

constexpr double PI = 3.14159265358979323846;



int seen[100005][3];

vector<int> graph[100005];



int main(){

    int n,m;

    cin >> n >> m;

    rep(i,n)rep(j,3) seen[i][j] = -1;

    rep(i,m){

        int a,b;

        cin >> a >> b;

        --a;--b;

        graph[a].push_back(b);

    }

    int s,t;

    cin >> s >> t;

    --s;--t;

    queue<pair<int,int>> q;

    q.push(P(3*s+0,0));

    while(!q.empty()){

        int now = q.front().first / 3;

        int c = q.front().first % 3;

        int len = q.front().second;

        q.pop();

        if(seen[now][c]>=0) continue;

        seen[now][c] = len;

        c = (c+1)%3;

        for(int j:graph[now]){

            if(seen[j][c]>=0) continue;

            q.push(P(3*j+c,len+1));

        }

    }

    if(seen[t][0]>=0) cout << seen[t][0] / 3 << endl;

    else cout << -1 << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int MAXN = 2e5;



const int INF = 1e9;



vector <int> g[MAXN];





int main()

{

#ifdef LOCAL

    freopen("input.txt", "r", stdin);

#endif // LOCAL

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int n, m;

    cin >> n >> m;

    vector <vector<int>> dist(n + 1, vector<int>(3, INF));

    for (int i = 0; i < m; i++) {

        int x, y;

        cin >> x >> y;

        g[x].push_back(y);

    }

    int s, t;

    cin >> s >> t;

    dist[s][0] = 0;

    queue <pair<int, int>> q;

    q.push({s, 0});

    while (!q.empty()) {

        int v = q.front().first;

        int r = q.front().second;

        q.pop();

        for (auto u : g[v]) {

            if (dist[v][r] + 1 < dist[u][(r + 1) % 3]) {

                dist[u][(r + 1) % 3] = dist[v][r] + 1;

                q.push({u, (r + 1) % 3});

            }

        }

    }

    if (dist[t][0] == INF) {

        cout << -1;

    } else {

        cout << dist[t][0] / 3;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1824214878100994x):
#include <bits/stdc++.h>

#define maxn 100005

using namespace std;

struct Node{

    int to,next;

}q[maxn];

int head[maxn],cnt=0,dis[maxn][10];

int n,m;

void add_edge(int from,int to){

    q[cnt].to=to;

    q[cnt].next=head[from];

    head[from]=cnt++;

}

typedef pair<int,int>pll;

void bfs(int x){

    queue<pll>que;

    que.push(pll(x,0));

    memset(dis,-1,sizeof(dis) );

    dis[x][0]=0;

    while(!que.empty()){

        x=que.front().first;

        int y=que.front().second;

        que.pop();

        for(int i=head[x];i!=-1;i=q[i].next){

            int to=q[i].to;

            int cost=(y+1)%3;

            if(dis[to][cost]>=0) continue;

            dis[to][cost]=dis[x][y]+1;

            que.push(pll(to,cost));

        }

    }

}

int main()

{

    memset(head,-1, sizeof(head));

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++){

        int from,to;

        scanf("%d%d",&from,&to);

        add_edge(from,to);

    }

    int s,t;

    scanf("%d%d",&s,&t);

    bfs(s);

    if(dis[t][0]>=0) dis[t][0]/=3;

    printf("%d\n",dis[t][0]);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int MAXN = 2e5;



const int INF = 1e9;



vector <int> g[MAXN];





int main()

{

#ifdef LOCAL

    freopen("input.txt", "r", stdin);

#endif // LOCAL

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int n, m;

    cin >> n >> m;

    vector <vector<int>> dist(n + 1, vector<int>(3, INF));

    for (int i = 0; i < m; i++) {

        int x, y;

        cin >> x >> y;

        g[x].push_back(y);

    }

    int s, t;

    cin >> s >> t;

    dist[s][0] = 0;

    queue <pair<int, int>> q;

    q.push({s, 0});

    while (!q.empty()) {

        int v = q.front().first;

        int r = q.front().second;

        q.pop();

        for (auto u : g[v]) {

            if (dist[v][r] + 1 < dist[u][(r + 1) % 3]) {

                dist[u][(r + 1) % 3] = dist[v][r] + 1;

                q.push({u, (r + 1) % 3});

            }

        }

    }

    if (dist[t][0] == INF) {

        cout << -1;

    } else {

        cout << dist[t][0] / 3;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8110054903195922x):
#include <bits/stdc++.h>



using namespace std ;



const int inf = 1e9 ;

const int MAX = 1e5 + 10 ;



int arr[MAX] , dist[MAX][3] ;

int n , m ;



vector< vector<int> >adj(MAX) ;



void dijkstra(int s)

{

	for(int i = 0 ; i <= n ; ++i)

		dist[i][0] = dist[i][1] = dist[i][2] = inf ;

	priority_queue< array<int , 3> , vector< array<int , 3> > , greater< array<int , 3> > >q ;

	dist[s][0] = 0 ;

	q.push({0 , s , 0}) ;

	while(!q.empty())

	{

		int cost = q.top()[0] ;

		int node = q.top()[1] ;

		int x = q.top()[2] ;

		q.pop() ;

		if(dist[node][x] < cost)

			continue ;

		for(auto &child : adj[node])

		{

			int ncost = cost ;

			if(x == 2)

				ncost++ ;

			if(ncost < dist[child][(x+1)%3])

			{

				dist[child][(x+1)%3] = ncost ;

				q.push({ncost , child , (x+1)%3}) ;

			}

		}

	}

	return ;

}



int main()

{

	ios_base::sync_with_stdio(0) ;

	cin.tie(0) ;

	cin>>n>>m ;

	for(int i = 0 ; i < m ; ++i)

	{

		int x , y ;

		cin>>x>>y ;

		adj[x].push_back(y) ;

	}

	int s , t ;

	cin>>s>>t ;

	dijkstra(s) ;

	int ans = dist[t][0] ;

	if(ans == inf)

		ans = -1 ;

	return cout<<ans<<"\n" , 0 ;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define maxn 100005

using namespace std;

struct Node{

    int to,next;

}q[maxn];

int head[maxn],cnt=0,dis[maxn][10];

int n,m;

void add_edge(int from,int to){

    q[cnt].to=to;

    q[cnt].next=head[from];

    head[from]=cnt++;

}

typedef pair<int,int>pll;

void bfs(int x){

    queue<pll>que;

    que.push(pll(x,0));

    memset(dis,-1,sizeof(dis) );

    dis[x][0]=0;

    while(!que.empty()){

        x=que.front().first;

        int y=que.front().second;

        que.pop();

        for(int i=head[x];i!=-1;i=q[i].next){

            int to=q[i].to;

            int cost=(y+1)%3;

            if(dis[to][cost]>=0) continue;

            dis[to][cost]=dis[x][y]+1;

            que.push(pll(to,cost));

        }

    }

}

int main()

{

    memset(head,-1, sizeof(head));

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++){

        int from,to;

        scanf("%d%d",&from,&to);

        add_edge(from,to);

    }

    int s,t;

    scanf("%d%d",&s,&t);

    bfs(s);

    if(dis[t][0]>=0) dis[t][0]/=3;

    printf("%d\n",dis[t][0]);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.531607391264227x):
#include <bits/stdc++.h>



using namespace std ;



const int inf = 1e9 ;

const int MAX = 1e5 + 10 ;



int arr[MAX] , dist[MAX][3] ;

int n , m ;



vector< vector<int> >adj(MAX) ;



void dijkstra(int s)

{

	for(int i = 0 ; i <= n ; ++i)

		dist[i][0] = dist[i][1] = dist[i][2] = inf ;

	priority_queue< array<int , 3> , vector< array<int , 3> > , greater< array<int , 3> > >q ;

	dist[s][0] = 0 ;

	q.push({0 , s , 0}) ;

	while(!q.empty())

	{

		int cost = q.top()[0] ;

		int node = q.top()[1] ;

		int x = q.top()[2] ;

		q.pop() ;

		if(dist[node][x] < cost)

			continue ;

		for(auto &child : adj[node])

		{

			int ncost = cost ;

			if(x == 2)

				ncost++ ;

			if(ncost < dist[child][(x+1)%3])

			{

				dist[child][(x+1)%3] = ncost ;

				q.push({ncost , child , (x+1)%3}) ;

			}

		}

	}

	return ;

}



int main()

{

	ios_base::sync_with_stdio(0) ;

	cin.tie(0) ;

	cin>>n>>m ;

	for(int i = 0 ; i < m ; ++i)

	{

		int x , y ;

		cin>>x>>y ;

		adj[x].push_back(y) ;

	}

	int s , t ;

	cin>>s>>t ;

	dijkstra(s) ;

	int ans = dist[t][0] ;

	if(ans == inf)

		ans = -1 ;

	return cout<<ans<<"\n" , 0 ;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int MAXN = 2e5;



const int INF = 1e9;



vector <int> g[MAXN];





int main()

{

#ifdef LOCAL

    freopen("input.txt", "r", stdin);

#endif // LOCAL

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int n, m;

    cin >> n >> m;

    vector <vector<int>> dist(n + 1, vector<int>(3, INF));

    for (int i = 0; i < m; i++) {

        int x, y;

        cin >> x >> y;

        g[x].push_back(y);

    }

    int s, t;

    cin >> s >> t;

    dist[s][0] = 0;

    queue <pair<int, int>> q;

    q.push({s, 0});

    while (!q.empty()) {

        int v = q.front().first;

        int r = q.front().second;

        q.pop();

        for (auto u : g[v]) {

            if (dist[v][r] + 1 < dist[u][(r + 1) % 3]) {

                dist[u][(r + 1) % 3] = dist[v][r] + 1;

                q.push({u, (r + 1) % 3});

            }

        }

    }

    if (dist[t][0] == INF) {

        cout << -1;

    } else {

        cout << dist[t][0] / 3;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8242861137481796x):
#include <bits/stdc++.h>

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;



typedef long long  ll;

typedef unsigned long long  ull;

#define lp(i,n)      for(int i=0;i<n;i++)

#define lpi(i,j,n)   for(int i=j;i<n;i++)

#define lpd(i,j,n)   for(int i=j;i>=n;i--)

#define MP           make_pair

#define clr(v, d)    (memset(v, d, sizeof(v)))

#define all(v)     (v.begin()),(v.end())

#define N 100005

const double pi = acos(-1);



ll n,t,m,k;



ll ans;

ll mod = 1e9 +7;

vector<int>adj[N];

int dis[N],vis[N][3];



queue<int>q;

void dfs(int node, int num, int reach){

  if(num==3){

    if(dis[node]==-1){

      dis[node]=reach;

      q.push(node);

    }

    return;

  }

  if(vis[node][num])return;

  vis[node][num]=1;

  for(auto& u:adj[node])dfs(u,num+1,reach);

}





int main() {

 

ios_base::sync_with_stdio(0);

cin.tie(0);cout.tie(0);

// freopen("e.txt","r",stdin); 

// freopen("e_out.txt","w",stdout); 

cout.precision(7);



cin>>n>>m;

lp(i,m){

  int x,y;

  cin>>x>>y;

  adj[x].push_back(y);

}

int S,T;

cin>>S>>T;

lp(i,n+1)dis[i]=-1;

q.push(S);

dis[S]=0;

while(!q.empty()){

  int node = q.front();

  q.pop();

  dfs(node,0,dis[node]+1);

}

cout<<dis[T];











  

}

  

 







// bool isPrime(ll h){

//      for(ll i=0;primes[i]*primes[i]<= h;i++)

//      if (h%primes[i]==0)

//      	return 0;

//      return h!=1;

//  }

 bool isPrime(ll g){

   if((g%2==0 && g>2) || g==1)return 0;

   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;

   return 1;   

 

 }
// Slower C++ solution:
#include <bits/stdc++.h>

#define maxn 100005

using namespace std;

struct Node{

    int to,next;

}q[maxn];

int head[maxn],cnt=0,dis[maxn][10];

int n,m;

void add_edge(int from,int to){

    q[cnt].to=to;

    q[cnt].next=head[from];

    head[from]=cnt++;

}

typedef pair<int,int>pll;

void bfs(int x){

    queue<pll>que;

    que.push(pll(x,0));

    memset(dis,-1,sizeof(dis) );

    dis[x][0]=0;

    while(!que.empty()){

        x=que.front().first;

        int y=que.front().second;

        que.pop();

        for(int i=head[x];i!=-1;i=q[i].next){

            int to=q[i].to;

            int cost=(y+1)%3;

            if(dis[to][cost]>=0) continue;

            dis[to][cost]=dis[x][y]+1;

            que.push(pll(to,cost));

        }

    }

}

int main()

{

    memset(head,-1, sizeof(head));

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++){

        int from,to;

        scanf("%d%d",&from,&to);

        add_edge(from,to);

    }

    int s,t;

    scanf("%d%d",&s,&t);

    bfs(s);

    if(dis[t][0]>=0) dis[t][0]/=3;

    printf("%d\n",dis[t][0]);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.5428391081820105x):
#include <bits/stdc++.h>

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;



typedef long long  ll;

typedef unsigned long long  ull;

#define lp(i,n)      for(int i=0;i<n;i++)

#define lpi(i,j,n)   for(int i=j;i<n;i++)

#define lpd(i,j,n)   for(int i=j;i>=n;i--)

#define MP           make_pair

#define clr(v, d)    (memset(v, d, sizeof(v)))

#define all(v)     (v.begin()),(v.end())

#define N 100005

const double pi = acos(-1);



ll n,t,m,k;



ll ans;

ll mod = 1e9 +7;

vector<int>adj[N];

int dis[N],vis[N][3];



queue<int>q;

void dfs(int node, int num, int reach){

  if(num==3){

    if(dis[node]==-1){

      dis[node]=reach;

      q.push(node);

    }

    return;

  }

  if(vis[node][num])return;

  vis[node][num]=1;

  for(auto& u:adj[node])dfs(u,num+1,reach);

}





int main() {

 

ios_base::sync_with_stdio(0);

cin.tie(0);cout.tie(0);

// freopen("e.txt","r",stdin); 

// freopen("e_out.txt","w",stdout); 

cout.precision(7);



cin>>n>>m;

lp(i,m){

  int x,y;

  cin>>x>>y;

  adj[x].push_back(y);

}

int S,T;

cin>>S>>T;

lp(i,n+1)dis[i]=-1;

q.push(S);

dis[S]=0;

while(!q.empty()){

  int node = q.front();

  q.pop();

  dfs(node,0,dis[node]+1);

}

cout<<dis[T];











  

}

  

 







// bool isPrime(ll h){

//      for(ll i=0;primes[i]*primes[i]<= h;i++)

//      if (h%primes[i]==0)

//      	return 0;

//      return h!=1;

//  }

 bool isPrime(ll g){

   if((g%2==0 && g>2) || g==1)return 0;

   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;

   return 1;   

 

 }
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

#define  ll long long

#define ld long double

#define f first

#define s second

const int N = 2e5+5;



int n , m , s , t;

vector<int> adj[N];



int bfs()

{

    queue< pair<int,int> > q;

    int d[n+2][4];

    for(int i=1; i<=n; i++)

    {

        d[i][0]=1e8 , d[i][1] =1e8 , d[i][2] = 1e8;

    }

    q.push({s , 0});

    d[s][0] = 0;



    while(q.size())

    {

        int node = q.front().f , mod = q.front().s;

        q.pop();



        for(auto ch : adj[node])

        {

            int m = (mod+1)%3;

            if (d[ch][m] == 1e8)

            {

                d[ch][m] = d[node][mod]+1;

                q.push({ch,m});

            }

        }

    }



    if (d[t][0] == 1e8) return -1;

    else return d[t][0]/3;

}



int main()

{



    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



    cin >> n >> m;

    for(int i=1; i<=m; i++)

    {

        int x,y;

        cin >> x >> y;

        adj[x].push_back(y);

    }



    cin >> s >> t;

    cout << bfs() << '\n';



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8246031682697914x):
#include <bits/stdc++.h>

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;



typedef long long  ll;

typedef unsigned long long  ull;

#define lp(i,n)      for(int i=0;i<n;i++)

#define lpi(i,j,n)   for(int i=j;i<n;i++)

#define lpd(i,j,n)   for(int i=j;i>=n;i--)

#define MP           make_pair

#define clr(v, d)    (memset(v, d, sizeof(v)))

#define all(v)     (v.begin()),(v.end())

#define N 100005

const double pi = acos(-1);



ll n,t,m,k;



ll ans;

ll mod = 1e9 +7;

vector<int>adj[N];

int dis[N],vis[N][3];



queue<int>q;

void dfs(int node, int num, int reach){

  if(num==3){

    if(dis[node]==-1){

      dis[node]=reach;

      q.push(node);

    }

    return;

  }

  if(vis[node][num])return;

  vis[node][num]=1;

  for(auto& u:adj[node])dfs(u,num+1,reach);

}





int main() {

 

ios_base::sync_with_stdio(0);

cin.tie(0);cout.tie(0);

// freopen("e.txt","r",stdin); 

// freopen("e_out.txt","w",stdout); 

cout.precision(7);



cin>>n>>m;

lp(i,m){

  int x,y;

  cin>>x>>y;

  adj[x].push_back(y);

}

int S,T;

cin>>S>>T;

lp(i,n+1)dis[i]=-1;

q.push(S);

dis[S]=0;

while(!q.empty()){

  int node = q.front();

  q.pop();

  dfs(node,0,dis[node]+1);

}

cout<<dis[T];











  

}

  

 







// bool isPrime(ll h){

//      for(ll i=0;primes[i]*primes[i]<= h;i++)

//      if (h%primes[i]==0)

//      	return 0;

//      return h!=1;

//  }

 bool isPrime(ll g){

   if((g%2==0 && g>2) || g==1)return 0;

   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;

   return 1;   

 

 }
// Slower C++ solution:
#include<bits/stdc++.h>

 

using namespace std;

 

#define INF 1000000007

#define LINF 1000000000000000007

 

typedef long long i64;

typedef pair<i64,i64> P;





int n, m, s, t;

vector<int> v[101010];

int dp[101010][3];



int main(){

	cin >> n >> m;

	for(int i = 0; i < m; i++){

		int a,b;

		cin >> a >> b;

		v[a].push_back(b);

	}

	cin >> s >> t;

	

	for(int i = 0; i < 101010; i++) for(int j = 0; j < 3; j++){

		dp[i][j] = INF;

	}

	int ans = INF;

	queue<pair<int,int>> q;

	q.push(make_pair(s, 0));

	dp[s][0] = 0;

	while(!q.empty()){

		pair<int,int> p = q.front();

		q.pop();

		int pos = p.first, cnt = p.second;

		for(int i = 0; i < v[pos].size(); i++){

			if(dp[v[pos][i]][(cnt+1)%3] <= cnt+1) continue;

			dp[v[pos][i]][(cnt+1) % 3] = cnt+1;

			q.push(make_pair(v[pos][i], cnt+1));

		}

	}

	

	if(dp[t][0] == INF){

		cout << -1 << endl;

	}

	else{

		cout << dp[t][0]/3 << endl;

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.381541361549305x):
#include<iostream>

#include<string>

#include<queue>

#include<algorithm>

#include<map>

#include<set>

#include<vector>



using namespace std;



#define INF 1000000007

#define LINF 1000000000000000007



typedef long long i64;

typedef pair<i64,i64> P;





int n, m, s, t;

vector<int> v[101010];

bool used[101010][3];



int main(){

	cin >> n >> m;

	for(int i = 0; i < m; i++){

		int a,b;

		cin >> a >> b;

		v[a].push_back(b);

	}

	cin >> s >> t;

	

	i64 ans = LINF;

	queue<P> q;

	q.push(P(s,0));

	while(!q.empty()){

		P p = q.front();

		q.pop();

		i64 now = p.first, cnt = p.second;

		if(used[now][cnt%3]) continue;

		used[now][cnt%3] = 1;

		if(now == t && cnt % 3 == 0){

			ans = min(ans, cnt/3);

		}

		for(int i = 0; i < v[now].size(); i++){

			q.push(P(v[now][i], cnt+1));

		}

	}

	

	if(ans == LINF) cout << -1 << endl;

	else cout << ans << endl;

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

using ll = long long;



const int maxn = 1e5+10;

const int INF = 1e9+10;



vector<int> g[maxn];

int p[maxn][3];



void bfs(int x){

	queue<pair<int,int>> q;

	q.push({x,0});

	p[x][0] = 0;

	while(!q.empty()){

		int nxt = q.front().first;

		int moves = q.front().second;

		q.pop();

		for(int i=0;i<g[nxt].size();++i){

			int v = g[nxt][i];

			if(p[nxt][moves]+1 < p[v][(moves+1)%3]){

				p[v][(moves+1)%3] = p[nxt][moves]+1;

				q.push({v,(moves+1)%3});

			}

		}

	}

}



void init(){

	for(int i=0;i<maxn;++i)

		for(int j=0;j<3;++j)

			p[i][j] = INF;

}



void solve(){

	int n,m,s,t;

	init();

	cin >> n >> m;

	for(int i=1;i<=m;++i){

		int u,v;

		cin >> u >> v;

		g[u].push_back(v);

	}

	cin >> s >> t;

	bfs(s);

	if(p[t][0] == INF){

		cout << -1 << '\n';

	}

	else{

		cout << p[t][0]/3 << '\n';

	}

}



int main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int t = 1;

	//cin >> t;

	while(t--){ 

		solve();

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3761411915745776x):
#include <iostream>

#include <bits/stdc++.h>

#define mod 1000000007

#define point complex<long long>

#define pi acos(-1)

#define pb push_back





typedef long long ll;



using namespace std;



void Fastio(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n, m, s, e;

vector<int>arr[100005];

int bfs(){

    queue<pair<int,int> >q;

    q.push({s, 0});

    int vis[n+1][3]={0};

    while(!q.empty()){

        int cur=q.front().first, d=q.front().second;

        q.pop();

        if(cur==e && d%3==0)

            return d/3;

            vis[cur][d%3]=1;

        for(auto i: arr[cur]){

            if(vis[i][(d+1)%3])continue;

            vis[i][(d+1)%3]=1;

            q.push({i, d+1});

        }

    }

    return -1;

}

int main()

{

    Fastio();

    int ttt=1; //cin>>ttt;

    while(ttt--){

        cin>>n>>m;

        for(int i=0; i<m; i++){

            int u, v; cin>>u>>v;

            arr[u].pb(v);

        }

        cin>>s>>e;

        cout<<bfs()<<'\n';

    }



    return 0;

}