結果

問題 No.1221 木 *= 3
ユーザー daikisuyamadaikisuyama
提出日時 2020-09-05 10:27:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 228,456 KB
最終ジャッジ日時 2023-08-18 15:24:34
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,528 KB
testcase_01 AC 62 ms
71,392 KB
testcase_02 AC 64 ms
71,504 KB
testcase_03 AC 65 ms
71,556 KB
testcase_04 AC 64 ms
71,508 KB
testcase_05 AC 63 ms
71,348 KB
testcase_06 AC 64 ms
71,600 KB
testcase_07 AC 708 ms
225,100 KB
testcase_08 AC 736 ms
227,520 KB
testcase_09 AC 687 ms
222,616 KB
testcase_10 AC 752 ms
228,456 KB
testcase_11 AC 745 ms
228,316 KB
testcase_12 AC 280 ms
115,200 KB
testcase_13 AC 272 ms
114,428 KB
testcase_14 AC 287 ms
114,360 KB
testcase_15 AC 284 ms
115,028 KB
testcase_16 AC 290 ms
114,912 KB
testcase_17 AC 315 ms
111,668 KB
testcase_18 AC 304 ms
111,744 KB
testcase_19 AC 318 ms
112,620 KB
testcase_20 AC 321 ms
113,096 KB
testcase_21 AC 332 ms
113,100 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