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

f=lambda:map(int,input().split())
N,M=f()
KKP=[[[] for _ in [0]*(N+1)] for _ in [0]*3]
for _ in [0]*M:
    a,b=f()
    KKP[0][a].append(b)
S,T=f()

for j in range(2):
    # j:回数
    for a in range(1,N+1):
        # a:頂点
        for b in KKP[j][a]:
            # KKP[j][a]:aからj+1回でたどり着ける頂点 b
            for c in KKP[0][b]:
                # bから1回でたどり着ける頂点 c
                if not c in KKP[j+1][a]:
                    KKP[j+1][a].append(c)

F=set([])
q=deque()
q.append((S,0))
res=-1
while q:
    node,score=q.popleft()
    if node in F:
        continue
    if T==node:
        res=score
        break
    F.add(node)
    for nnode in KKP[2][node]:
        if nnode in F:
            continue
        q.append((nnode,score+1))
print(res)

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)

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

f=lambda:map(int,input().split())
N,M=f()
KKP=[[set([]) for _ in [0]*(N+1)] for _ in [0]*3]
for _ in [0]*M:
    a,b=f()
    KKP[0][a].add(b)
S,T=f()

for j in range(2):
    # j:回数
    for a in range(1,N+1):
        # a:頂点
        for b in KKP[j][a]:
             # KKP[j][a]:aからj+1回でたどり着ける頂点
            for c in KKP[0][b]:
                # bから1回でたどり着ける頂点
                KKP[j+1][a].add(c)

F=set([])
q=deque()
q.append((S,0))
res=-1
while q:
    node,score=q.popleft()
    if node in F:
        continue
    if T==node:
        res=score
        break
    F.add(node)
    for nnode in KKP[2][node]:
        if nnode in F:
            continue
        q.append((nnode,score+1))
print(res)

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)

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

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]
for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
    
def check(i):
    res=[i]
    for i in range(3):
        tmpF=set([])
        for r in res:
            for node in G[r]:
                if node in tmpF:
                    continue
                tmpF.add(node)
        res=list(tmpF)
    return res

# KKP=[[]]+[check(i+1) for i in range(N)]

F=set([])
q=deque()
q.append((S,0))
res=-1
while q:
    node,score=q.popleft()
    if node in F:
        continue
    if T==node:
        res=score
        break
    F.add(node)
    for nnode in check(node):
        if nnode in F:
            continue
        q.append((nnode,score+1))
print(res)

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)

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

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]
for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
    
def check(i):
    res=[i]
    for i in range(3):
        tmpF=set([])
        for r in res:
            for node in G[r]:
                if node in tmpF:
                    continue
                tmpF.add(node)
        res=list(tmpF)
    return res

KKP=[[]]+[check(i+1) for i in range(N)]

F=set([])
q=deque()
q.append((S,0))
res=-1
while q:
    node,score=q.popleft()
    if node in F:
        continue
    if T==node:
        res=score
        break
    F.add(node)
    for nnode in KKP[node]:
        if nnode in F:
            continue
        q.append((nnode,score+1))
    if T in F:
        break
print(res)

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)

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

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]
for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
    
def check(i):
    tmpF=[0]*(N+1)
    res=[i]
    for i in range(3):
        tmpres=[]
        tmpF=[0]*(N+1)
        for r in res:
            for node in G[r]:
                if tmpF[node]:
                    continue
                tmpres.append(node)
                tmpF[node]=1
        res=tmpres[:]
    return res

KKP=[[]]+[check(i+1) for i in range(N)]

F=[-1]*(N+1)
F[0]=-1
q=deque()
q.append((S,0))
while q:
    node,par=q.popleft()
    if F[node]>=0:
        continue
    F[node]=F[par]+1
    for nnode in KKP[node]:
        if F[nnode]>=0:
            continue
        q.append((nnode,node))
    if F[T]>=0:
        break
print(F[T])

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)

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

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]
for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
    
def check(i):
    tmpF=[0]*(N+1)
    res=[(i,[i])]
    for i in range(3):
        tmpres=[]
        for r,par in res:
            for node in G[r]:
                tmpres.append((node,r))
        res=tmpres[:]
    return list(set([i for i,j in res]))

KKP=[[]]+[check(i+1) for i in range(N)]

F=[-1]*(N+1)
F[0]=-1
q=deque()
q.append((S,0))
while q:
    node,par=q.popleft()
    if F[node]>=0:
        continue
    F[node]=F[par]+1
    for nnode in KKP[node]:
        if F[nnode]>=0:
            continue
        q.append((nnode,node))
    if F[T]>=0:
        break
print(F[T])

Fixed submission:
# ABC132 E
from collections import deque

f=lambda:map(int,input().split())
N,M=f()
G=[[] for _ in [0]*(N+1)]

for _ in [0]*M:
    a,b=f()
    G[a].append(b)
S,T=f()
S=(S,0)
T=(T,0)

q=deque()
q.append(S)
F=set()
res=-1
while q:
    node,r=q.popleft()
    if (node,r%3) in F:
        continue
    if (node,r%3) == T:
        res=r//3
        break
    F.add((node,r%3))
    for next_node in G[node]:
        if (next_node,(r+1)%3) in F:
            continue
        q.append((next_node,r+1))
print(res)