結果

問題 No.417 チューリップバブル
ユーザー Yukino DX.Yukino DX.
提出日時 2023-11-11 12:17:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 696 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 17,044 KB
最終ジャッジ日時 2023-11-11 12:17:13
合計ジャッジ時間 7,168 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
9,984 KB
testcase_01 AC 42 ms
9,984 KB
testcase_02 AC 42 ms
9,984 KB
testcase_03 AC 42 ms
9,984 KB
testcase_04 AC 31 ms
9,984 KB
testcase_05 AC 31 ms
9,984 KB
testcase_06 AC 60 ms
9,984 KB
testcase_07 AC 59 ms
9,984 KB
testcase_08 TLE -
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 #

from itertools import count

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(crr, prv):
    for nxt, _ in g[crr]:
        if nxt != prv:
            dfs(nxt, crr)

    for nxt, t in g[crr]:
        for i in range(m, -1, -1):
            for j in count(0):
                if i < 2 * t + j:
                    break
                dp[crr][i] = max(dp[crr][i], dp[crr][i - (2 * t + j)] + dp[nxt][j])

    for i in range(m + 1):
        dp[crr][i] += u[crr]


dfs(0, n)
print(dp[0][m])
0