結果

問題 No.417 チューリップバブル
ユーザー shinichishinichi
提出日時 2023-01-29 11:23:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 670 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 16,364 KB
最終ジャッジ日時 2023-09-11 19:46:07
合計ジャッジ時間 6,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
16,364 KB
testcase_01 AC 21 ms
7,752 KB
testcase_02 AC 22 ms
7,752 KB
testcase_03 AC 22 ms
7,828 KB
testcase_04 AC 16 ms
7,828 KB
testcase_05 AC 17 ms
7,816 KB
testcase_06 AC 31 ms
7,868 KB
testcase_07 AC 31 ms
7,868 KB
testcase_08 AC 1,350 ms
8,424 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**5)


N, M = map(int, input().split())
U = [int(input()) for _ in range(N)]
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    tree[a].append((b, c))
    tree[b].append((a, c))

# 使用した時間を入れる
dp = [[U[i]] * (M + 1) for i in range(N)]


def dfs(v, p=-1):
    for nv, nw in tree[v]:
        if nv == p:
            continue
        dfs(nv, v)
        for m1 in range(M, -1, -1):
            for m2 in range(M-m1+1):
                t = m1 + 2*nw + m2
                if t <= M:
                    dp[v][t] = max(dp[v][t], dp[v][m1] + dp[nv][m2])

dfs(0)
print(max(dp[0]))
0