結果

問題 No.1221 木 *= 3
ユーザー daikisuyamadaikisuyama
提出日時 2020-09-05 10:27:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 808 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 224,212 KB
最終ジャッジ日時 2024-05-05 20:36:15
合計ジャッジ時間 9,616 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 38 ms
51,812 KB
testcase_02 AC 39 ms
52,096 KB
testcase_03 AC 38 ms
51,712 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 37 ms
51,840 KB
testcase_06 AC 39 ms
51,840 KB
testcase_07 AC 733 ms
216,784 KB
testcase_08 AC 808 ms
224,212 KB
testcase_09 AC 651 ms
215,408 KB
testcase_10 AC 736 ms
223,844 KB
testcase_11 AC 714 ms
223,744 KB
testcase_12 AC 261 ms
114,368 KB
testcase_13 AC 266 ms
113,840 KB
testcase_14 AC 281 ms
113,144 KB
testcase_15 AC 275 ms
113,288 KB
testcase_16 AC 301 ms
113,620 KB
testcase_17 AC 329 ms
111,744 KB
testcase_18 AC 305 ms
111,432 KB
testcase_19 AC 306 ms
111,412 KB
testcase_20 AC 326 ms
111,572 KB
testcase_21 AC 327 ms
112,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**7)
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