結果

問題 No.1340 おーじ君をさがせ
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-16 03:58:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 778 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,824 KB
最終ジャッジ日時 2024-11-26 22:28:17
合計ジャッジ時間 36,505 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7

def main():

    n, m, t = map(int, input().split())
    A = [[0]*n for i in range(n)]
    for i in range(m):
        a, b = map(int, input().split())
        A[b][a] = 1
    #print(A)
    # A*B
    import numpy as np

    #A**n
    def mat_pow(A, n, mod):
        size = len(A)
        res = np.eye(size, dtype=np.object)
        while n > 0:
            if n & 1 == 1:
                res = res @ A
                res %= mod
            A = A @ A
            A %= mod
            n = n>>1
        return res

    X = [0]*n
    X[0] = 1
    X = np.array(X)
    A = np.array(A)
    A = mat_pow(A, t, mod)
    ans = 0
    for i in range(n):
        s = A[i]@X
        if s:
            ans += 1
    #print(A)
    print(ans)

if __name__ == '__main__':
    main()
0