結果

問題 No.30 たこやき工場
ユーザー 👑 colognecologne
提出日時 2022-01-23 14:15:35
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 638 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 76,440 KB
最終ジャッジ日時 2023-08-19 19:04:56
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,224 KB
testcase_01 AC 73 ms
71,360 KB
testcase_02 AC 73 ms
71,124 KB
testcase_03 AC 75 ms
71,224 KB
testcase_04 AC 76 ms
71,028 KB
testcase_05 AC 78 ms
71,320 KB
testcase_06 AC 77 ms
71,420 KB
testcase_07 AC 76 ms
71,148 KB
testcase_08 AC 77 ms
75,100 KB
testcase_09 AC 77 ms
75,388 KB
testcase_10 AC 92 ms
76,440 KB
testcase_11 AC 78 ms
75,304 KB
testcase_12 AC 75 ms
71,256 KB
testcase_13 AC 73 ms
71,152 KB
testcase_14 AC 78 ms
75,296 KB
testcase_15 AC 79 ms
75,128 KB
testcase_16 AC 79 ms
75,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline


def main():
    N = int(input())
    M = int(input())

    adj = [[] for i in range(N)]
    for i in range(M):
        P, Q, R = map(int, input().split())
        adj[R-1].append((Q, P-1))

    ans = [None]*N

    def solve(x):
        if ans[x] is not None:
            return ans[x]

        ret = [0]*(N-1)
        for q, p in adj[x]:
            s = solve(p)
            for i in range(N-1):
                ret[i] += s[i]*q

        if len(adj[x]) == 0:
            ret[x] = 1

        ans[x] = ret
        return ret

    print(*solve(N-1), sep='\n')


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