結果

問題 No.1221 木 *= 3
ユーザー 37zigen37zigen
提出日時 2020-09-07 13:14:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 579 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 54,832 KB
最終ジャッジ日時 2023-08-19 16:35:55
合計ジャッジ時間 10,780 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,796 KB
testcase_01 AC 16 ms
7,916 KB
testcase_02 AC 15 ms
7,792 KB
testcase_03 AC 14 ms
7,820 KB
testcase_04 AC 14 ms
7,928 KB
testcase_05 AC 14 ms
7,768 KB
testcase_06 AC 13 ms
7,960 KB
testcase_07 AC 545 ms
52,644 KB
testcase_08 AC 566 ms
54,832 KB
testcase_09 AC 579 ms
52,640 KB
testcase_10 AC 562 ms
53,384 KB
testcase_11 AC 571 ms
53,480 KB
testcase_12 AC 480 ms
34,340 KB
testcase_13 AC 481 ms
33,996 KB
testcase_14 AC 489 ms
34,248 KB
testcase_15 AC 490 ms
34,100 KB
testcase_16 AC 504 ms
34,176 KB
testcase_17 AC 527 ms
37,020 KB
testcase_18 AC 535 ms
38,572 KB
testcase_19 AC 573 ms
35,684 KB
testcase_20 AC 531 ms
35,616 KB
testcase_21 AC 562 ms
35,556 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