Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, U: "List[int]", V: "List[int]", S: int, T: int):
    S -= 1
    T -= 1
    adj = [[] for i in range(N)]
    for u, v in zip(U, V):
        adj[u-1].append(v-1)
    color = [[] for i in range(N)]
    color[S] = [0]
    Q = [(0, S)]

    while len(Q) > 0:
        d, u = heapq.heappop(Q)
        if u == T and d % 3 == 0:
            print(d // 3)
            return
        for v in adj[u]:
            if (d+1) % 3 in color[v]:
                continue
            heapq.heappush(Q, (d+1, v))
            color[v].append(d+1 % 3)

    print(-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, U: "List[int]", V: "List[int]", S: int, T: int):
    S -= 1
    T -= 1
    adj = [[] for i in range(N)]
    for u, v in zip(U, V):
        adj[u-1].append(v-1)
    color = [[0, 0, 0] for i in range(N)]
    color[S][0] = 1
    Q = [(0, S)]

    while len(Q) > 0:
        d, u = heapq.heappop(Q)
        if u == T and d % 3 == 0:
            print(d // 3)
            return
        for v in adj[u]:
            if color[v][(d+1) % 3] == 1:
                continue
            heapq.heappush(Q, (d+1, v))
            color[v][(d+1) % 3] = 1

    print(-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, U: "List[int]", V: "List[int]", S: int, T: int):
    S -= 1
    T -= 1
    adj = [[] for i in range(N)]
    for u, v in zip(U, V):
        adj[u-1].append(v-1)
    Q = [(0, S, frozenset([S]))]
    visited = defaultdict(lambda: 0)

    while len(Q) > 0:
        d, u, route = heapq.heappop(Q)
        if u == T:
            visited[route] += 1
        if u == T and d % 3 == 0:
            print(d // 3)
            return
        if u == T and visited[route] >= 3:
            print(-1)
            return
        for v in adj[u]:
            heapq.heappush(Q, (d+1, v, route | {v}))

    print(-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, U: "List[int]", V: "List[int]", S: int, T: int):
    S -= 1
    T -= 1
    adj = [[] for i in range(N)]
    for u, v in zip(U, V):
        adj[u-1].append(v-1)
    color = [[0, 0, 0] for i in range(N)]
    color[S][0] = 1
    Q = [(0, S)]

    while len(Q) > 0:
        d, u = heapq.heappop(Q)
        if u == T and d % 3 == 0:
            print(d // 3)
            return
        for v in adj[u]:
            if color[v][(d+1) % 3] == 1:
                continue
            heapq.heappush(Q, (d+1, v))
            color[v][(d+1) % 3] = 1

    print(-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)

if __name__ == '__main__':
    main()