Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

ELIST=[set() for i in range(N+1)]

for x,y in E:
    ELIST[x].append(y)


DIS=[-1]*(N+1)
from collections import deque
DIS[S]=0
S=deque([S])

SA=[0]
while S:
    x=S.pop()
    NEWS=deque()

    for to in ELIST[x]:
        if DIS[to]==-1:
            DIS[to]=i
            NEWS.append(to)
        if DIS[to]<i:
            SA.append(i-to)
        

    i+=1
    S=NEWS

if DIS[G]==-1:
    print(-1)
else:
    SA.sort()
    for s in SA:
        if (DIS[G]+s)%3==0:
            print((DIS[G]+s))

            
        
    


Fixed submission:
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

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

for x,y in E:
    ELIST[x].append(y)

DIS=[[-1,-1,-1] for i in range(N+1)]
DIS[S][0]=0

from collections import deque

S=deque([S])
i=1

while S:
    #print(S)
    NEWS=deque()
    while S:     
        x=S.pop()

        for to in ELIST[x]:
            if DIS[to][i%3]==-1:
                DIS[to][i%3]=i
                NEWS.append(to)

    i+=1
    S=NEWS

print(DIS[G][0]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import time
time0=time.time()
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

ELIST=[set() for i in range(N+1)]

for x,y in E:
    ELIST[x].add(y)

check=[10**8]*(N+1)
check[S]=0

def three_step_from(S,i):

    ONE=set()

    for s in S:

        ONE=ONE|ELIST[s]

    TWO=set()
    for one in ONE:
        
        TWO=TWO|ELIST[one]

    THREE=set()
    for two in TWO:
        THREE=THREE|ELIST[two]

    RET=set()

    for three in THREE:
        if check[three]!=10**8:
            continue
        check[three]=i
        RET.add(three)

    return RET

i=1
NOW={S}
while NOW:
    NOW=three_step_from(NOW,i)
    i+=1

    if check[G]!=10**8:
        print(check[G])
        sys.exit()

    if time.time()-time0>1.9:
        print(-1)
        sys.exit()

else:
    print(-1)
    
        


Fixed submission:
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

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

for x,y in E:
    ELIST[x].append(y)

DIS=[[-1,-1,-1] for i in range(N+1)]
DIS[S][0]=0

from collections import deque

S=deque([S])
i=1

while S:
    #print(S)
    NEWS=deque()
    while S:     
        x=S.pop()

        for to in ELIST[x]:
            if DIS[to][i%3]==-1:
                DIS[to][i%3]=i
                NEWS.append(to)

    i+=1
    S=NEWS

print(DIS[G][0]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

ELIST=[set() for i in range(N+1)]

for x,y in E:
    ELIST[x].add(y)

check=[float("inf")]*(N+1)
check[S]=0

def three_step_from(S,i):

    ONE=set()

    for s in S:

        ONE=ONE|ELIST[s]

    TWO=set()
    for one in ONE:
        
        TWO=TWO|ELIST[one]

    THREE=set()
    for two in TWO:
        THREE=THREE|ELIST[two]

    RET=set()

    for three in THREE:
        if check[three]!=float("inf"):
            continue
        check[three]=i
        RET.add(three)

    return RET

i=1
NOW={S}
while NOW:
    NOW=three_step_from(NOW,i)
    i+=1

if check[G]==float("inf"):
    print(-1)
else:
    print(check[G])
    
        


Fixed submission:
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]
S,G=map(int,input().split())

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

for x,y in E:
    ELIST[x].append(y)

DIS=[[-1,-1,-1] for i in range(N+1)]
DIS[S][0]=0

from collections import deque

S=deque([S])
i=1

while S:
    #print(S)
    NEWS=deque()
    while S:     
        x=S.pop()

        for to in ELIST[x]:
            if DIS[to][i%3]==-1:
                DIS[to][i%3]=i
                NEWS.append(to)

    i+=1
    S=NEWS

print(DIS[G][0]//3)