Buggy python submission (verdict: Time Limit Exceeded):
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    q = queue.Queue()
    q.put(s)

    while not q.empty():
        u = q.get()
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK and d[v] == INFTY:
                d[v] = d[u] + 1
                q.put(v)

    return d
def rec(s, i, depth):
    if depth == 3:
        kkpgraph[s].append(i)
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    rec(i, i, 0)
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


Fixed submission:
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    q = queue.Queue()
    q.put(s)

    while not q.empty():
        u = q.get()
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK and d[v] == INFTY:
                d[v] = d[u] + 1
                color[v] = GRAY
                q.put(v)

    return d

def rec(s, i, depth):
    if depth == 3:
        kkpgraph[s].append(i)
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    rec(i, i, 0)
    kkpgraph[i] = list(set(kkpgraph[i]))
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


Fixed submission:
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    q = queue.Queue()
    q.put(s)

    while not q.empty():
        u = q.get()
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK and d[v] == INFTY:
                d[v] = d[u] + 1
                color[v] = GRAY
                q.put(v)

    return d

def rec(s, i, depth):
    if depth == 3:
        if is_visited[i]:
            return
        kkpgraph[s].append(i)
        is_visited[i] = True
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    is_visited = [False for i in range(N+1)]
    rec(i, i, 0)
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


Fixed submission:
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK:
                if d[u] + 1 < d[v]:
                    d[v] = d[u] + 1
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

def rec(s, i, depth):
    if depth == 3:
        kkpgraph[s].append(i)
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    rec(i, i, 0)
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


Fixed submission:
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK:
                if d[u] + 1 < d[v]:
                    d[v] = d[u] + 1
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

def rec(s, i, depth):
    if depth == 3:
        kkpgraph[s].append(i)
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    rec(i, i, 0)
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


Fixed submission:
import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)