結果
問題 | No.417 チューリップバブル |
ユーザー |
![]() |
提出日時 | 2017-12-13 17:14:15 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 811 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 117 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-12-14 09:59:48 |
合計ジャッジ時間 | 10,457 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
n, m = map(int, input().split())u_ls = [int(input()) for i in range(n)]c_ls = [set() for i in range(n)]for i in range(n - 1):a, b, c = map(int, input().split())c_ls[a].add((b, c))c_ls[b].add((a, c))memo = [[-1] * (m // 2 + 1) for i in range(n)]def solve(pos, parent, max_m):memo[pos][0] = u_ls[pos]for next_pos, cost in c_ls[pos]:if next_pos == parent:continuenext_max_m = max_m - costsolve(next_pos, pos, next_max_m)memo_pos = memo[pos][:]for pos_m in range(next_max_m + 1):if memo_pos[pos_m] < 0:continuefor next_m in range(next_max_m - pos_m + 1):if memo[next_pos][next_m] < 0:continuesum_m = pos_m + next_m + costmemo[pos][sum_m] = max(memo_pos[pos_m] + memo[next_pos][next_m], memo[pos][sum_m])solve(0, -1, m // 2)print(max(memo[0]))