結果

問題 No.1340 おーじ君をさがせ
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-15 22:08:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 717 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 80,892 KB
最終ジャッジ日時 2024-05-05 21:47:32
合計ジャッジ時間 11,510 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 38 ms
52,096 KB
testcase_02 AC 38 ms
52,096 KB
testcase_03 AC 38 ms
51,840 KB
testcase_04 AC 36 ms
52,480 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 36 ms
52,224 KB
testcase_07 AC 36 ms
52,352 KB
testcase_08 AC 36 ms
52,352 KB
testcase_09 AC 37 ms
52,352 KB
testcase_10 AC 50 ms
65,024 KB
testcase_11 AC 140 ms
75,776 KB
testcase_12 AC 63 ms
67,072 KB
testcase_13 AC 235 ms
77,312 KB
testcase_14 AC 224 ms
76,288 KB
testcase_15 AC 199 ms
76,032 KB
testcase_16 AC 60 ms
66,176 KB
testcase_17 AC 105 ms
75,916 KB
testcase_18 AC 141 ms
76,232 KB
testcase_19 AC 52 ms
63,616 KB
testcase_20 AC 46 ms
61,184 KB
testcase_21 AC 149 ms
76,160 KB
testcase_22 AC 717 ms
80,892 KB
testcase_23 AC 151 ms
76,288 KB
testcase_24 AC 499 ms
76,544 KB
testcase_25 AC 63 ms
72,960 KB
testcase_26 AC 59 ms
69,632 KB
testcase_27 AC 57 ms
67,968 KB
testcase_28 AC 68 ms
73,488 KB
testcase_29 AC 51 ms
65,536 KB
testcase_30 AC 159 ms
76,192 KB
testcase_31 AC 517 ms
77,156 KB
testcase_32 AC 479 ms
76,544 KB
testcase_33 AC 472 ms
76,804 KB
testcase_34 AC 446 ms
76,416 KB
testcase_35 AC 530 ms
77,000 KB
testcase_36 AC 38 ms
52,608 KB
testcase_37 AC 46 ms
64,640 KB
testcase_38 AC 503 ms
76,800 KB
testcase_39 AC 176 ms
76,648 KB
testcase_40 AC 186 ms
76,672 KB
testcase_41 AC 185 ms
76,544 KB
testcase_42 AC 44 ms
59,136 KB
testcase_43 AC 43 ms
59,392 KB
testcase_44 AC 46 ms
61,696 KB
testcase_45 AC 44 ms
60,416 KB
testcase_46 AC 150 ms
76,160 KB
testcase_47 AC 151 ms
76,160 KB
testcase_48 AC 168 ms
76,672 KB
testcase_49 AC 163 ms
76,240 KB
testcase_50 AC 160 ms
76,288 KB
testcase_51 AC 163 ms
75,904 KB
testcase_52 AC 256 ms
76,288 KB
testcase_53 AC 252 ms
76,416 KB
testcase_54 AC 254 ms
76,284 KB
testcase_55 AC 212 ms
76,372 KB
testcase_56 AC 45 ms
60,160 KB
testcase_57 AC 45 ms
60,544 KB
testcase_58 AC 37 ms
52,352 KB
testcase_59 AC 113 ms
71,552 KB
testcase_60 AC 37 ms
52,224 KB
testcase_61 AC 111 ms
71,552 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