Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


input = sys.stdin.readline
n, m = map(int, input().split())
info = tuple(map(int, input().split()) for i in range(m))
s, t = map(int, input().split())

graph = [[] for i in range(n)]
for i, j in info:
    graph[i-1].append(j-1)


graph2 = [[] for i in range(n)]
q = deque()
q.append((s - 1, 0))
INF = float("inf")
visited = [INF] * n
visited[0] = 0

while q:
    pos, times = q.popleft()
    for i in graph[pos]:
        if (times + 1) % 3 != 0:
            q.append((i, times + 1))
        if (times + 1) % 3 == 0 and times + 1 < visited[i]:
            visited[i] = times + 1
            q.append((i, times+1))

if visited[t-1] == float("inf"):
    print(-1)
else:
    print(visited[t-1]//3)
    

Fixed submission:
import sys
from collections import deque


input = sys.stdin.readline
n, m = map(int, input().split())
info = tuple(map(int, input().split()) for i in range(m))
s, t = map(int, input().split())

graph = [[] for i in range(n)]
for i, j in info:
    graph[i-1].append(j-1)

q = deque()
q.append((s - 1, 0))
INF = 10 ** 10
visited = [10 ** 10] * n
visited_1 = [10 ** 10] * n
visited_2 = [10 ** 10] * n
visited[s - 1] = 0
while q:
    pos, times = q.popleft()
    for i in graph[pos]:
        if (times + 1) % 3 == 1 and times + 1 < visited_1[i]:
            visited_1[i] = times + 1
            q.append((i, times + 1))

        elif (times + 1) % 3 == 2 and times + 1 < visited_2[i]:
            visited_2[i] = times + 1
            q.append((i, times + 1))
            
        elif (times + 1) % 3 == 0 and times + 1 < visited[i]:
            visited[i] = times + 1
            q.append((i, times + 1))

if visited[t - 1] == 10 ** 10:
    print(-1)
else:
    print(visited[t-1]//3)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
s, t = map(int, input().split())

graph = [[] for i in range(n)]
for i, j in info:
    graph[i-1].append(j-1)


graph2 = [[] for i in range(n)]
q = deque()
q.append([s - 1, 0])
visited = [float("inf")] * n
visited[0] = 0

while q:
    pos, times = q.popleft()
    for i in graph[pos]:
        if (times + 1) % 3 != 0:
            q.append([i, times + 1])
        if (times + 1) % 3 == 0 and times + 1 < visited[i]:
            visited[i] = times + 1
            q.append([i, times+1])

if visited[t-1] == float("inf"):
    print(-1)
else:
    print(visited[t-1]//3)
    

Fixed submission:
import sys
from collections import deque


input = sys.stdin.readline
n, m = map(int, input().split())
info = tuple(map(int, input().split()) for i in range(m))
s, t = map(int, input().split())

graph = [[] for i in range(n)]
for i, j in info:
    graph[i-1].append(j-1)

q = deque()
q.append((s - 1, 0))
INF = 10 ** 10
visited = [10 ** 10] * n
visited_1 = [10 ** 10] * n
visited_2 = [10 ** 10] * n
visited[s - 1] = 0
while q:
    pos, times = q.popleft()
    for i in graph[pos]:
        if (times + 1) % 3 == 1 and times + 1 < visited_1[i]:
            visited_1[i] = times + 1
            q.append((i, times + 1))

        elif (times + 1) % 3 == 2 and times + 1 < visited_2[i]:
            visited_2[i] = times + 1
            q.append((i, times + 1))
            
        elif (times + 1) % 3 == 0 and times + 1 < visited[i]:
            visited[i] = times + 1
            q.append((i, times + 1))

if visited[t - 1] == 10 ** 10:
    print(-1)
else:
    print(visited[t-1]//3)