結果

問題 No.1221 木 *= 3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-10-24 01:48:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 853 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 60,984 KB
最終ジャッジ日時 2023-09-28 19:59:34
合計ジャッジ時間 15,295 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,776 KB
testcase_01 AC 15 ms
7,824 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
7,872 KB
testcase_04 AC 17 ms
7,924 KB
testcase_05 AC 16 ms
7,792 KB
testcase_06 AC 15 ms
7,796 KB
testcase_07 AC 845 ms
59,840 KB
testcase_08 AC 832 ms
60,984 KB
testcase_09 AC 853 ms
59,644 KB
testcase_10 AC 852 ms
60,844 KB
testcase_11 AC 840 ms
60,936 KB
testcase_12 AC 707 ms
42,048 KB
testcase_13 AC 699 ms
41,904 KB
testcase_14 AC 707 ms
41,820 KB
testcase_15 AC 713 ms
41,972 KB
testcase_16 AC 731 ms
41,900 KB
testcase_17 AC 799 ms
45,480 KB
testcase_18 AC 800 ms
45,700 KB
testcase_19 AC 805 ms
45,112 KB
testcase_20 AC 796 ms
45,080 KB
testcase_21 AC 805 ms
44,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
edges = [[] for i in range(n)]
for i in range(n - 1):
    u, v = map(int, input().split())
    edges[u - 1].append(v - 1)
    edges[v - 1].append(u - 1)
dp = [[0] * 2 for i in range(n)]
def dfs(now, prev):
    dp[now][0] = a[now]
    for nex in edges[now]:
        if nex != prev:
            dfs(nex, now)
            dp[now][0] += max(dp[nex][0], dp[nex][1])
            dp[now][1] += max(dp[nex][0], dp[nex][1] + b[now] + b[nex])
    return None
dfs(0, -1)
print(max(dp[0]))
0