結果

問題 No.1340 おーじ君をさがせ
ユーザー shotoyooshotoyoo
提出日時 2021-01-15 22:10:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 890 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 81,808 KB
最終ジャッジ日時 2023-08-18 16:37:33
合計ジャッジ時間 16,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,316 KB
testcase_01 AC 67 ms
71,072 KB
testcase_02 AC 67 ms
71,172 KB
testcase_03 AC 71 ms
71,020 KB
testcase_04 AC 67 ms
71,120 KB
testcase_05 AC 67 ms
71,180 KB
testcase_06 AC 67 ms
71,324 KB
testcase_07 AC 69 ms
71,192 KB
testcase_08 AC 67 ms
71,288 KB
testcase_09 AC 66 ms
70,852 KB
testcase_10 AC 78 ms
76,052 KB
testcase_11 AC 195 ms
77,200 KB
testcase_12 AC 97 ms
76,372 KB
testcase_13 AC 295 ms
77,600 KB
testcase_14 AC 328 ms
77,348 KB
testcase_15 AC 291 ms
77,088 KB
testcase_16 AC 96 ms
76,388 KB
testcase_17 AC 152 ms
76,844 KB
testcase_18 AC 204 ms
76,992 KB
testcase_19 AC 80 ms
76,036 KB
testcase_20 AC 74 ms
76,144 KB
testcase_21 AC 205 ms
77,172 KB
testcase_22 AC 890 ms
81,808 KB
testcase_23 AC 201 ms
77,220 KB
testcase_24 AC 734 ms
77,884 KB
testcase_25 AC 96 ms
77,152 KB
testcase_26 AC 89 ms
76,552 KB
testcase_27 AC 85 ms
76,604 KB
testcase_28 AC 104 ms
77,144 KB
testcase_29 AC 81 ms
76,644 KB
testcase_30 AC 228 ms
77,380 KB
testcase_31 AC 757 ms
78,308 KB
testcase_32 AC 715 ms
78,048 KB
testcase_33 AC 707 ms
78,108 KB
testcase_34 AC 638 ms
77,784 KB
testcase_35 AC 766 ms
78,024 KB
testcase_36 AC 72 ms
71,316 KB
testcase_37 AC 81 ms
76,156 KB
testcase_38 AC 760 ms
78,016 KB
testcase_39 AC 255 ms
77,532 KB
testcase_40 AC 269 ms
77,456 KB
testcase_41 AC 263 ms
77,436 KB
testcase_42 AC 77 ms
76,088 KB
testcase_43 AC 74 ms
75,316 KB
testcase_44 AC 83 ms
75,980 KB
testcase_45 AC 81 ms
75,972 KB
testcase_46 AC 216 ms
77,384 KB
testcase_47 AC 223 ms
77,556 KB
testcase_48 AC 244 ms
77,340 KB
testcase_49 AC 229 ms
77,112 KB
testcase_50 AC 231 ms
77,268 KB
testcase_51 AC 237 ms
77,208 KB
testcase_52 AC 387 ms
77,120 KB
testcase_53 AC 373 ms
77,152 KB
testcase_54 AC 387 ms
77,144 KB
testcase_55 AC 318 ms
77,408 KB
testcase_56 AC 79 ms
75,944 KB
testcase_57 AC 80 ms
76,268 KB
testcase_58 AC 68 ms
71,256 KB
testcase_59 AC 167 ms
76,068 KB
testcase_60 AC 70 ms
71,068 KB
testcase_61 AC 162 ms
76,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
_print = lambda *x: print(*x, file=sys.stderr)

### 行列積 matrix multiplication
### 繰り返し2乗法 kurikae

M = 10**9+7
def mul(a,b):
    """行列a,bの積
    aかbがNone のとき、単位行列として扱う
    """
    if a is None:
        return b
    elif b is None:
        return a
    n,m = len(a), len(a[0])
    k,l = len(b), len(b[0])
    # k==m
    out = [[0]*l for _ in range(n)]
    for i in range(n):
        for j in range(l):
            for p in range(m):
                out[i][j] |= (a[i][p]&b[p][j])
    return out
def mulk(m, k):
    """a^kを求める
    """
    ans = None
    tmp = m
    while k>0:
        if k&1:
            ans = mul(ans, tmp)
        tmp = mul(tmp, tmp)
        k = k>>1
    return ans
def mul2(m,a):
    """行列と配列の積
    """
    k,l = len(m), len(m[0])
#     ll = len(a)
    ans = [0]*k
    for i in range(k):
        for j in range(l):
            ans[i] |= (m[i][j] & a[j])
    return ans

n,m,t = list(map(int, input().split()))
val = [[0]*n for _ in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    val[a][b] = 1
if t==0:
    print(1)
else:
    valt = mulk(val,t)
    b = [0]*n
    b[0] = 1
    valtt = [[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            valtt[i][j] = valt[j][i]
    ans = mul2(valtt,b)
    print(sum(ans))
0