結果

問題 No.417 チューリップバブル
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-10 18:11:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 71,992 KB
最終ジャッジ日時 2024-05-01 05:35:52
合計ジャッジ時間 4,017 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
59,872 KB
testcase_01 AC 42 ms
59,672 KB
testcase_02 AC 42 ms
61,372 KB
testcase_03 WA -
testcase_04 AC 36 ms
52,640 KB
testcase_05 AC 36 ms
52,124 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 47 ms
63,552 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 38 ms
58,180 KB
testcase_33 AC 43 ms
61,304 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**9

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))

topo = []
par = [-1] * N
que = [0]
while que:
    s = que.pop()
    topo.append(s)
    for t, c in g[s]:
        if t == par[s]:
            continue
        par[t] = s
        que.append(t)

dp = [[0] for _ in range(N)]
for s in topo[::-1]:
    for t, c in g[s]:
        if t == par[s]:
            continue
        c *= 2
        merge = [0] * (len(dp[s]) + len(dp[t]) + c - 1)
        for i, vs in enumerate(dp[s]):
            for j, vt in enumerate(dp[t]):
                merge[i+j+c] = max(merge[i+j+c], vs + vt)
        if len(merge) > M + 1:
            merge = merge[:M + 1]
        dp[s] = merge
    u = U[s]
    dp[s] = [u + ds for ds in dp[s]]
print(dp[s][M])
0