結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,740 KB
testcase_02 AC 16 ms
7,772 KB
testcase_03 AC 16 ms
7,820 KB
testcase_04 AC 16 ms
7,856 KB
testcase_05 AC 17 ms
7,872 KB
testcase_06 AC 17 ms
7,824 KB
testcase_07 AC 703 ms
51,988 KB
testcase_08 AC 698 ms
54,164 KB
testcase_09 AC 704 ms
51,804 KB
testcase_10 AC 718 ms
53,952 KB
testcase_11 AC 699 ms
54,052 KB
testcase_12 AC 601 ms
34,272 KB
testcase_13 AC 588 ms
34,972 KB
testcase_14 AC 608 ms
34,960 KB
testcase_15 AC 596 ms
34,960 KB
testcase_16 AC 607 ms
34,964 KB
testcase_17 AC 682 ms
37,116 KB
testcase_18 AC 679 ms
38,652 KB
testcase_19 AC 688 ms
36,956 KB
testcase_20 AC 685 ms
36,956 KB
testcase_21 AC 682 ms
36,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(2*10**5)
N=int(input())
dp1=[0]+list(map(int,input().split()))
dp2=[0]*(N+1)
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):
    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