Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())

for i in o:
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=set()
seen.add(3*s)
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if t not in seen:
            dq.append((t,c+1))
            seen.add(now)

print("-1")


Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,input().split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase

s,T=map(int,input().split())
from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=set()
seen.add(3*s)
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if t not in seen:
            dq.append((t,c+1))
            seen.add(now)

print("-1")


Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
def f():
    import sys
    input=sys.stdin.buffer.readline
    inputs=sys.stdin.buffer.readlines
    sys.setrecursionlimit(10**9)
    n,m=map(int,input().split())
    edges=[[] for i in range(3+3*n)]
    for i in range(m):
        """#weighted->erase_,__,___=map(int,input().split())
        edges[_].append((__,___))
        #undirected->erase#edges[__].append((_,___))
        """
        _,__=map(int,input().split())
        _*=3;__*=3
        edges[_].append(__+1)
        edges[_+1].append(__+2)
        edges[_+2].append(__)

        #undirected->erase#edges[__].append(_)
        """
    """#weighted->erase

    s,T=map(int,input().split())
    from collections import deque
    dq=deque([])
    dq.append((3*s,0))
    T*=3
    seen=set()
    seen.add(3*s)
    while dq:
        now,c=dq.popleft()
        if now==T :print(c//3);exit()
        for t in edges[now]:
            if t not in seen:
                dq.append((t,c+1))
                seen.add(now)

    print("-1")
if __name__ == "__main__":
    f()

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
def f():
    import sys
    input=sys.stdin.buffer.readline
    inputs=sys.stdin.buffer.readlines
    sys.setrecursionlimit(10**9)
    n,m=map(int,input().split())
    edges=[[] for i in range(3+3*n)]
    for i in range(m):
        """#weighted->erase_,__,___=map(int,input().split())
        edges[_].append((__,___))
        #undirected->erase#edges[__].append((_,___))
        """
        _,__=map(int,input().split())
        _*=3;__*=3
        edges[_].append(__+1)
        edges[_+1].append(__+2)
        edges[_+2].append(__)

        #undirected->erase#edges[__].append(_)
        """
    """#weighted->erase

    s,T=map(int,input().split())
    from collections import deque
    dq=deque([])
    dq.append((3*s,0))
    T*=3
    seen=set()
    while dq:
        now,c=dq.popleft()
        seen.add(now)
        for t in edges[now]:
            if t==T :print((c+1)//3);exit()
            if t not in seen:
                dq.append((t,c+1))
    print("-1")
if __name__ == "__main__":
    f()

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase

s,T=map(int,input().split())
from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=set()
while dq:
    now,c=dq.popleft()
    seen.add(now)
    for t in edges[now]:
        if t==T :print((c+1)//3);exit()
        if t not in seen:
            dq.append((t,c+1))
print("-1")

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
edges=[[] for i in range(1+n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    edges[_].append(__)
    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase

s,T=map(int,input().split())
from collections import deque
dq=deque([])
dq.append((s,0,0))
seen=[set()for i in [0,0,0]]
while dq:
    now,o,c=dq.popleft()
    seen[o].add(now)
    nex=(o+1)%3
    for t in edges[now]:
        if t==T and nex==0:print((c+1)//3);exit()
        if not(t in seen[nex]):
            dq.append((t,nex,c+1))
print("-1")

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
edges=[[] for i in range(1+n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    edges[_].append(__)
    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase
s,t=map(int,input().split())
r1,r2,r0=set(),set(),set()
from collections import deque
d0=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
d1=deque([])
d2=deque([])
d0.append((s,0))
r0.add(s)
while d0 :
    while d0:
        a,c=d0.pop()
        for ne in edges[a]:
            if ne not in r1:d1.appendleft((ne,c))
    while d1:
        a,c=d1.pop()
        for ne in edges[a]:
            if ne not in r2:d2.appendleft((ne,c))
    while d2:
        a,c=d2.pop()
        for ne in edges[a]:
            if ne not in r0:
                if ne != t:d0.appendleft((ne,c+1))
                else:print(c+1);exit()
print(-1)

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
edges=[[] for i in range(1+n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    edges[_].append(__)
    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase
s,t=map(int,input().split())
r1,r2,r0=set(),set(),set()
from collections import deque
d0=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
d1=deque([])
d2=deque([])
d0.append((s,0))
r0.add(s)
while d0 :
    while d0:
        a,c=d0.pop()
        for ne in edges[a]:
            if ne not in r1:d1.appendleft((ne,c))
    while d1:
        a,c=d1.pop()
        for ne in edges[a]:
            if ne not in r2:d2.appendleft((ne,c))
    while d2:
        a,c=d2.pop()
        for ne in edges[a]:
            if ne not in r0:
                if ne != t:d0.appendleft((ne,c+1))
                else:print(c+1);exit()
print(-1)

Fixed submission:
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")