結果

問題 No.417 チューリップバブル
ユーザー kept1994kept1994
提出日時 2022-10-24 21:21:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,420 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 83,640 KB
最終ジャッジ日時 2023-09-15 22:58:56
合計ジャッジ時間 27,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,480 KB
testcase_01 AC 79 ms
76,080 KB
testcase_02 AC 81 ms
75,744 KB
testcase_03 AC 78 ms
76,248 KB
testcase_04 AC 72 ms
71,152 KB
testcase_05 AC 73 ms
71,268 KB
testcase_06 AC 79 ms
76,204 KB
testcase_07 AC 78 ms
75,884 KB
testcase_08 AC 114 ms
76,080 KB
testcase_09 AC 162 ms
76,196 KB
testcase_10 AC 189 ms
75,776 KB
testcase_11 AC 580 ms
76,076 KB
testcase_12 AC 577 ms
76,076 KB
testcase_13 AC 261 ms
76,084 KB
testcase_14 AC 885 ms
76,084 KB
testcase_15 AC 132 ms
76,080 KB
testcase_16 AC 129 ms
76,184 KB
testcase_17 AC 508 ms
75,772 KB
testcase_18 AC 508 ms
76,116 KB
testcase_19 AC 510 ms
76,020 KB
testcase_20 AC 1,784 ms
78,088 KB
testcase_21 AC 1,763 ms
78,200 KB
testcase_22 AC 1,768 ms
78,144 KB
testcase_23 AC 1,764 ms
77,908 KB
testcase_24 AC 76 ms
75,516 KB
testcase_25 AC 1,774 ms
78,116 KB
testcase_26 AC 224 ms
76,080 KB
testcase_27 AC 1,259 ms
77,752 KB
testcase_28 AC 1,759 ms
78,332 KB
testcase_29 AC 1,754 ms
78,356 KB
testcase_30 AC 1,761 ms
78,268 KB
testcase_31 AC 1,747 ms
78,192 KB
testcase_32 AC 72 ms
75,200 KB
testcase_33 AC 120 ms
76,128 KB
testcase_34 AC 406 ms
75,976 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    U = [int(input()) for _ in range(N)]
    dp = [[U[i]] * (M + 1) for i in range(N)] # dp[node][i] := nodeにおいて、残り時間restで得られる最大のスコア
    for _ in range(N - 1):
        aa, bb, cc = map(int, input().split())
        G[aa].append((bb, cc))
        G[bb].append((aa, cc))

    def dfs(pre: int, now: int):
        for next, cost in G[now]: 
            if next == pre: 
                continue
            dfs(now, next)
            for rest in range(M, cost * 2 - 1, -1):
                for j in range(rest - cost * 2 + 1): 
                    dp[now][rest] = max(dp[now][rest], dp[now][rest - (j + cost * 2)] + dp[next][j])
                    # 子ノードnextに行くには(j + cost)だけ必要になる。
                    # -> その分を確保し、引いた後に残る時間でノードnowにおいて取れる最大のスコアdp[now][rest - (j + cost)] ( <- 他の子ノードを回る分があるのでこれを考慮する)
                    # -> と、子ノードnextに行ったことで得られるスコア dp[next][j] で更新する。
        return
    dfs(-1, 0)
    ans = -1
    for i in range(M + 1):
        # print(dp[0][i]) 
        ans = max(ans, dp[0][i]) 
    print(ans)    
    return


if __name__ == '__main__':
    main()
0