結果

問題 No.1340 おーじ君をさがせ
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-15 22:08:32
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 82,000 KB
最終ジャッジ日時 2023-08-18 16:36:57
合計ジャッジ時間 13,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
70,848 KB
testcase_01 AC 70 ms
71,312 KB
testcase_02 AC 70 ms
71,248 KB
testcase_03 AC 70 ms
71,272 KB
testcase_04 AC 69 ms
71,084 KB
testcase_05 AC 69 ms
71,200 KB
testcase_06 AC 67 ms
71,032 KB
testcase_07 AC 68 ms
71,152 KB
testcase_08 AC 66 ms
70,952 KB
testcase_09 AC 68 ms
70,844 KB
testcase_10 AC 88 ms
75,768 KB
testcase_11 AC 158 ms
76,720 KB
testcase_12 AC 87 ms
76,192 KB
testcase_13 AC 261 ms
78,360 KB
testcase_14 AC 250 ms
77,284 KB
testcase_15 AC 218 ms
77,176 KB
testcase_16 AC 82 ms
76,312 KB
testcase_17 AC 123 ms
76,816 KB
testcase_18 AC 165 ms
77,104 KB
testcase_19 AC 78 ms
76,124 KB
testcase_20 AC 73 ms
76,320 KB
testcase_21 AC 170 ms
77,164 KB
testcase_22 AC 751 ms
82,000 KB
testcase_23 AC 159 ms
77,324 KB
testcase_24 AC 532 ms
77,792 KB
testcase_25 AC 91 ms
76,956 KB
testcase_26 AC 83 ms
76,404 KB
testcase_27 AC 82 ms
76,608 KB
testcase_28 AC 99 ms
77,004 KB
testcase_29 AC 79 ms
76,288 KB
testcase_30 AC 182 ms
77,604 KB
testcase_31 AC 530 ms
78,284 KB
testcase_32 AC 498 ms
77,692 KB
testcase_33 AC 498 ms
77,804 KB
testcase_34 AC 462 ms
77,872 KB
testcase_35 AC 525 ms
78,144 KB
testcase_36 AC 68 ms
70,904 KB
testcase_37 AC 77 ms
75,944 KB
testcase_38 AC 536 ms
78,040 KB
testcase_39 AC 195 ms
77,340 KB
testcase_40 AC 201 ms
77,528 KB
testcase_41 AC 199 ms
77,448 KB
testcase_42 AC 73 ms
76,220 KB
testcase_43 AC 76 ms
76,080 KB
testcase_44 AC 76 ms
76,260 KB
testcase_45 AC 72 ms
76,004 KB
testcase_46 AC 166 ms
77,320 KB
testcase_47 AC 177 ms
77,408 KB
testcase_48 AC 184 ms
77,408 KB
testcase_49 AC 178 ms
77,204 KB
testcase_50 AC 184 ms
77,176 KB
testcase_51 AC 183 ms
77,152 KB
testcase_52 AC 280 ms
77,384 KB
testcase_53 AC 274 ms
77,164 KB
testcase_54 AC 283 ms
77,172 KB
testcase_55 AC 228 ms
77,372 KB
testcase_56 AC 74 ms
75,980 KB
testcase_57 AC 74 ms
76,280 KB
testcase_58 AC 70 ms
71,256 KB
testcase_59 AC 136 ms
76,248 KB
testcase_60 AC 71 ms
71,120 KB
testcase_61 AC 136 ms
76,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

NFAの状態数
行列べき乗じゃん!!



"""

import sys
from sys import stdin

mod = 998244353

#行列A,Bの積(不可能だとエラー,modに0以下の値を指定するとmodを取らなくなる)
def matrix_mul(A,B):
 
    ans = [ [0] * len(B[0]) for i in range(len(A)) ]
 
    for ai in range(len(A)):
 
        for bj in range(len(B[0])):
 
            now = 0
            for same in range(len(A[0])):
                now |= A[ai][same] & B[same][bj]
            ans[ai][bj] = now
    return ans
 
#行列Aのx乗(当然正方行列じゃないとだめ)
def matrix_pow(A,x):
 
    B = [[A[i][j] for j in range(len(A[0]))] for i in range(len(A))]
    ans = [[0] * len(A[0]) for i in range(len(A))]
    for i in range(len(A)):
        ans[i][i] = 1
 
    while x > 0:
        if x % 2 == 1:
            ans = matrix_mul(ans,B)
        B = matrix_mul(B,B)
 
        x//=2
    return ans

N,M,T = map(int,stdin.readline().split())

H = [[0] * N for i in range(N)]
for i in range(M):
    a,b = map(int,stdin.readline().split())
    H[a][b] = 1

A = [[0] * N]
A[0][0] = 1

ans = matrix_mul(A,matrix_pow(H,T))
#print (ans)
print (sum(ans[0]))
0