結果

問題 No.1221 木 *= 3
ユーザー qumazakiqumazaki
提出日時 2020-09-05 02:03:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 939 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 142,652 KB
最終ジャッジ日時 2023-08-17 21:13:28
合計ジャッジ時間 7,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,764 KB
testcase_01 AC 71 ms
71,184 KB
testcase_02 AC 71 ms
71,180 KB
testcase_03 AC 70 ms
70,928 KB
testcase_04 WA -
testcase_05 AC 71 ms
71,076 KB
testcase_06 AC 72 ms
71,120 KB
testcase_07 AC 340 ms
136,124 KB
testcase_08 AC 307 ms
128,028 KB
testcase_09 AC 315 ms
128,228 KB
testcase_10 AC 314 ms
128,148 KB
testcase_11 AC 311 ms
128,256 KB
testcase_12 AC 279 ms
142,652 KB
testcase_13 AC 284 ms
134,360 KB
testcase_14 AC 291 ms
134,124 KB
testcase_15 AC 286 ms
134,564 KB
testcase_16 AC 293 ms
134,884 KB
testcase_17 AC 295 ms
134,332 KB
testcase_18 AC 308 ms
127,988 KB
testcase_19 AC 310 ms
127,792 KB
testcase_20 AC 317 ms
127,756 KB
testcase_21 AC 332 ms
127,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = [0] + list(map(int,readline().split()))
b = [0] + list(map(int,readline().split()))
if(n==1):
    print(max(0,a[0]))
    exit()
data = list(map(int,read().split()))

links = [[] for _ in range(n+1)]
it = iter(data)
for u,v in zip(it,it):
    links[u].append(v)
    links[v].append(u)

stack = [1]
done = [0] * (n+1)
done[1] = 1
tp = []
child = [[] for _ in range(n+1)]
while(stack):
    i = stack.pop()
    tp.append(i)
    for j in links[i]:
        if(done[j] == 1):
            continue
        done[j] = 1
        child[i].append(j)
        stack.append(j)

scores = [[0,0] for _ in range(n+1)]

for i in tp[::-1]:
    for j in child[i]:
        scores[i][0] += max(scores[j][0] + b[i] + b[j], scores[j][1])
        scores[i][1] += max(scores[j])
    scores[i][1] += a[i]

print(max(scores[1]))
0