結果

問題 No.1112 冥界の音楽
ユーザー tanon710tanon710
提出日時 2020-07-11 00:30:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 76,120 KB
最終ジャッジ日時 2024-04-20 02:07:14
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
68,236 KB
testcase_01 AC 44 ms
62,628 KB
testcase_02 AC 37 ms
52,920 KB
testcase_03 AC 42 ms
61,976 KB
testcase_04 AC 39 ms
61,232 KB
testcase_05 AC 42 ms
60,780 KB
testcase_06 AC 69 ms
72,352 KB
testcase_07 AC 35 ms
53,184 KB
testcase_08 AC 43 ms
61,972 KB
testcase_09 AC 57 ms
68,736 KB
testcase_10 AC 45 ms
61,056 KB
testcase_11 AC 56 ms
67,896 KB
testcase_12 AC 39 ms
62,152 KB
testcase_13 AC 76 ms
73,488 KB
testcase_14 AC 72 ms
72,904 KB
testcase_15 AC 56 ms
68,120 KB
testcase_16 AC 33 ms
52,388 KB
testcase_17 AC 56 ms
68,976 KB
testcase_18 AC 56 ms
67,764 KB
testcase_19 AC 37 ms
52,468 KB
testcase_20 AC 53 ms
66,692 KB
testcase_21 AC 73 ms
72,764 KB
testcase_22 AC 75 ms
72,852 KB
testcase_23 AC 56 ms
68,128 KB
testcase_24 AC 36 ms
53,292 KB
testcase_25 AC 35 ms
54,180 KB
testcase_26 AC 43 ms
61,524 KB
testcase_27 AC 43 ms
62,128 KB
testcase_28 AC 44 ms
62,400 KB
testcase_29 AC 34 ms
53,576 KB
testcase_30 AC 58 ms
71,204 KB
testcase_31 AC 45 ms
63,836 KB
testcase_32 AC 61 ms
70,352 KB
testcase_33 AC 48 ms
62,080 KB
testcase_34 AC 32 ms
52,960 KB
testcase_35 AC 42 ms
62,224 KB
testcase_36 AC 88 ms
76,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=10**9+7

def calc(mat1,mat2):
    n=len(mat1)
    ret=[[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            tmp=0
            for k in range(n):
                tmp+=mat1[i][k]*mat2[k][j]
                tmp%=mod
            ret[i][j]=tmp
    return ret

k,m,n=map(int,input().split())
n-=2
edge=[list(map(int,input().split())) for _ in range(m)]
vec=[0]*(k**2)
mat=[[0]*(k**2) for _ in range(k**2)]
for p,q,r in edge:
    if p==1:
        vec[(p-1)*k+(q-1)]=1
    mat[(q-1)*k+(r-1)][(p-1)*k+(q-1)]=1
tmp=[[0]*(k**2) for _ in range(k**2)]
for i in range(k**2):
    tmp[i][i]=1
for i in range(60):
    if n&(1<<i):
        tmp=calc(tmp,mat)
    mat=calc(mat,mat)
cnt=[0]*(k**2)
for i in range(k**2):
    tcnt=0
    for j in range(k**2):
        tcnt+=tmp[i][j]*vec[j]
        tcnt%=mod
    cnt[i]=tcnt
ans=0
for i in range(k):
    ans+=cnt[i*k]
    ans%=mod
print(ans)
0