結果

問題 No.417 チューリップバブル
ユーザー rlangevinrlangevin
提出日時 2024-01-24 20:56:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,050 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 76,984 KB
最終ジャッジ日時 2024-01-24 20:57:07
合計ジャッジ時間 23,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,584 KB
testcase_01 AC 44 ms
61,844 KB
testcase_02 WA -
testcase_03 AC 45 ms
61,844 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 38 ms
53,460 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 46 ms
61,816 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 42 ms
59,572 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
M //= 2
U = [0] * N
for i in range(N):
    U[i] = int(input())
    
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, c = map(int, input().split())
    G[u].append((v, c))
    G[v].append((u, c))
    

def non_rec_dfs(s):
    stack = [s]
    dp = [[0] * (M + 1) for _ in range(N)]
    for i in range(N):
        dp[i][0] = U[i]
        
    par = [-1] * N
    while stack:
        u = stack.pop()
        if u >= 0:
            stack.append(~u)
            for v, c in G[u]:
                if v == par[u]:
                    continue
                par[v] = u
                stack.append(v)
        else:
            u = ~u
            for i in range(M, -1, -1):
                for v, c in G[u]:
                    for j in range(M + 1):
                        if i - c - j < 0:
                            break
                        dp[u][i] = max(dp[u][i],  dp[u][i - c - j] + dp[v][j])
                        
    return max(dp[0])

print(non_rec_dfs(0))
0