結果
| 問題 |
No.1221 木 *= 3
|
| コンテスト | |
| ユーザー |
qumazaki
|
| 提出日時 | 2020-09-05 02:03:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 939 bytes |
| コンパイル時間 | 525 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 134,336 KB |
| 最終ジャッジ日時 | 2024-11-26 21:34:52 |
| 合計ジャッジ時間 | 6,956 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 WA * 1 |
ソースコード
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]))
qumazaki