結果

問題 No.1221 木 *= 3
ユーザー 37zigen37zigen
提出日時 2020-09-07 13:14:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 57,420 KB
最終ジャッジ日時 2024-05-06 23:34:41
合計ジャッジ時間 12,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 27 ms
10,752 KB
testcase_07 AC 710 ms
56,628 KB
testcase_08 AC 729 ms
57,420 KB
testcase_09 AC 722 ms
55,036 KB
testcase_10 AC 713 ms
57,136 KB
testcase_11 AC 751 ms
55,996 KB
testcase_12 AC 641 ms
37,784 KB
testcase_13 AC 633 ms
37,588 KB
testcase_14 AC 639 ms
37,604 KB
testcase_15 AC 640 ms
37,544 KB
testcase_16 AC 634 ms
37,592 KB
testcase_17 AC 687 ms
39,704 KB
testcase_18 AC 691 ms
41,336 KB
testcase_19 AC 700 ms
39,600 KB
testcase_20 AC 686 ms
39,652 KB
testcase_21 AC 708 ms
38,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(2*10**5)
N=int(input())
dp1=[0]+list(map(int,input().split()))
dp2=[0]*(N+1) # remain
b=[0]+list(map(int,input().split()))
g=[[] for _ in range(N+1)]
for _ in range(N-1):
    u,v=map(int,input().split())
    g[u].append(v)
    g[v].append(u)
def dfs(v,p):
    s=0
    for u in g[v]:
        if u==p:
            continue
        dfs(u,v)
        dp1[v]+=max(dp1[u],dp2[u])
        dp2[v]+=max(dp1[u],dp2[u]+b[u]+b[v])
dfs(1,0)
print(max(dp1[1],dp2[1]))
0