結果

問題 No.417 チューリップバブル
ユーザー neko0774neko0774
提出日時 2023-01-31 13:44:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 698 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 12,864 KB
最終ジャッジ日時 2023-09-13 07:08:42
合計ジャッジ時間 5,845 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
7,776 KB
testcase_01 AC 24 ms
7,848 KB
testcase_02 AC 25 ms
7,788 KB
testcase_03 AC 25 ms
7,816 KB
testcase_04 AC 15 ms
7,804 KB
testcase_05 AC 16 ms
7,756 KB
testcase_06 AC 36 ms
7,820 KB
testcase_07 AC 35 ms
7,800 KB
testcase_08 AC 1,923 ms
8,472 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def main():
    N, M = map(int, input().split())
    U = [int(input()) for _ in range(N)]
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        A,B,C = map(int, input().split())
        G[A].append([B, C])
        G[B].append([A, C])

    dp = [[0]*(M+1) for _ in range(N)]
    def dfs(x, par=-1):
        dp[x][0] = U[x]
        for nx, t in G[x]:
            if nx==par:
                continue
            dfs(nx, x)
            for m in range(M+1)[::-1]:
                for mm in range(M+1):
                    T = m+mm+2*t
                    if T<M+1: dp[x][T] = max(dp[x][T], dp[x][m]+dp[nx][mm])
    dfs(0)
    print(max(dp[0]))


main()
0