結果

問題 No.1221 木 *= 3
ユーザー daikisuyamadaikisuyama
提出日時 2020-09-05 10:27:23
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 588 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 114,824 KB
最終ジャッジ日時 2023-08-18 15:22:45
合計ジャッジ時間 6,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
71,500 KB
testcase_01 AC 59 ms
71,560 KB
testcase_02 AC 57 ms
71,132 KB
testcase_03 AC 58 ms
71,500 KB
testcase_04 AC 58 ms
71,240 KB
testcase_05 AC 59 ms
71,368 KB
testcase_06 AC 62 ms
71,380 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 247 ms
114,272 KB
testcase_13 AC 245 ms
114,236 KB
testcase_14 AC 258 ms
114,824 KB
testcase_15 AC 253 ms
114,492 KB
testcase_16 AC 259 ms
114,212 KB
testcase_17 AC 269 ms
111,596 KB
testcase_18 AC 269 ms
111,836 KB
testcase_19 AC 282 ms
111,768 KB
testcase_20 AC 279 ms
111,816 KB
testcase_21 AC 283 ms
111,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
tree=[[] for i in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    tree[u-1].append(v-1)
    tree[v-1].append(u-1)
check=[False]*n
dp=[[0,0] for i in range(n)]

def dfs(i):
    global n,a,b,tree,check,dp
    #頂点iを消さない場合
    dp[i]=[a[i],0]
    for j in tree[i]:
        if not check[j]:
            check[j]=True
            dfs(j)
            dp[i][0]+=max(dp[j][0],dp[j][1])
            dp[i][1]+=max(dp[j][0],dp[j][1]+b[i]+b[j])

check[0]=True
dfs(0)
print(max(dp[0]))
0