Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
uv = [[] for _ in range(n)]
for i in range(m):
  u,v = map(lambda x:int(x)-1,input().split())
  uv[u].append(v)
s,t = map(lambda x:int(x)-1,input().split())
time = 0
now = {s}
flag = 0
for _ in range(n):
  time += 1
  tmp = set()
  for x in now:
    for y in uv[x]:
      tmp.add(y)
  now = tmp
  time += 1
  tmp = set()
  for x in now:
    for y in uv[x]:
      tmp.add(y)
  now = tmp
  time += 1
  tmp = set()
  for x in now:
    for y in uv[x]:
      tmp.add(y)
  now = tmp
  if t in now:
    flag = 1
    break
if flag == 1:
  print(time//3)
else:
  print(-1)

Fixed submission:
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
uv = [[] for _ in range(n)]
for i in range(m):
  u,v = map(lambda x:int(x)-1,input().split())
  uv[u].append(v)
s,t = map(lambda x:int(x)-1,input().split())
time = 0
now = {s}
flag = 0
while time < 3*n:
  time += 1
  tmp = set()
  for x in now:
    for y in uv[x]:
      tmp.add(y)
  now = tmp
  if time % 3 == 0:
    if t in now:
      flag = 1
      break
if flag == 1:
  print(time//3)
else:
  print(-1)

Fixed submission:
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
uv = [[] for _ in range(n)]
for i in range(m):
  u,v = map(lambda x:int(x)-1,input().split())
  uv[u].append(v)
s,t = map(lambda x:int(x)-1,input().split())
time = 0
now = {s}
flag = 0
while time < 3*n:
  time += 1
  tmp = set()
  for x in now:
    for y in uv[x]:
      tmp.add(y)
  now = tmp
  if time % 3 == 0:
    if t in now:
      flag = 1
      break
if flag == 1:
  print(time//3)
else:
  print(-1)

Fixed submission:
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
uv = [[] for _ in range(n)]
for i in range(m):
  u,v = map(lambda x:int(x)-1,input().split())
  uv[u].append(v)
s,t = map(lambda x:int(x)-1,input().split())
time = 0
now = [s]
flag = 0
while time < 3*n:
  time += 1
  tmp = []
  for x in now:
    for y in uv[x]:
      tmp.append(y)
  now = tmp
  if time % 3 == 0:
    if t in now:
      flag = 1
      break
if flag == 1:
  print(time//3)
else:
  print(-1)

Fixed submission:
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(int,input().split()))
uv = [[] for ni in range(n)]
for i in range(m):
  u,v = map(lambda x:int(x)-1,input().split())
  uv[u].append(v)
s,t = list(map(lambda x:int(x)-1,input().split()))
flag = 0
time = 0
a = [set() for ni in range(n)]
a[s].add(0)
while time < 3*n:
  time += 1
  ad = []
  for ni in range(n):
    ad.append(set(map(lambda x:x+1,a[ni])))
  for ni in range(n):
    luv = len(uv[ni])
    for luvi in range(luv):
      a[uv[ni][luvi]] |= ad[ni]
  for x in a[t]:
    if x%3 == 0:
      flag = 1
      ans = x//3
  if flag == 1:
    break
if flag==0:
  print(-1)
else:
  print(ans)

Fixed submission:
n,m = map(int,input().split())
pst = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  pst[a].append(b)
s,t = map(int,input().split())
s -= 1
t -= 1
cnt = [[0,0,0] for _ in range(n)]
cnt[s][0] = 1
now = [s]
time = 0
while now:
  time += 1
  last = now
  now = []
  for x in last:
    for y in pst[x]:
      if cnt[y][time%3] == 0:
        cnt[y][time%3] = 1
        now.append(y)
  #print(time,cnt,now)
  if cnt[t][0] == 1:
    print(time//3)
    break
else:
  print(-1)