Problem: Ken loves _ken-ken-pa_ (Japanese version of hopscotch). Today, he will play it on a directed graph G. G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.  First, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken- ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.  Determine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa.

Submission attempts (in order):
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, M: int, edges, S: int, T: int):
    S -= 1
    T -= 1
    now = np.zeros(10**5)
    now[S] = 1
    seen = now > 0
    c = 0
    s = 0
    while s < np.count_nonzero(seen):
        c += 1
        s = np.count_nonzero(seen)
        now = now.dot(edges)
        if now[T]:
            print(c)
            sys.exit(0)
        seen |= (now > 0)
    print(-1)
    return


# Generated by 1.1.6 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
    Mat = np.zeros((10**5, 10**5))
    for _ in range(M):
        u, v = int(next(tokens)) - 1, int(next(tokens))-1
        Mat[u][v] = 1
        #Mat[v][u] = 1


    Three = np.copy(Mat)
    for _ in range(2):
        Three = Three.dot(Mat)

    #print(Three)

    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, Three, S, T)

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, M: int, G, S: int, T: int):
    S -= 1
    T -= 1
    now = deque([S])
    dist = [0 for _ in range(N * 3)]
    while now:
        p = now.popleft()
        for n in G[p]:
            if dist[n] != 0:
                continue
            dist[n] = dist[p] + 1
            if n == T:
                print(dist[n] // 3)
                exit()
            now.append(n)
    print(-1)
    return


# Generated by 1.1.6 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
    G = tuple(set() for _ in range(N * 3))
    for _ in range(M):
        u, v = int(next(tokens)) - 1, int(next(tokens))-1
        G[u].add(v + N)
        G[u + N].add(v + 2 * N)
        G[u + 2 * N].add(v)

    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, G, S, T)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted