結果
| 問題 | No.1221 木 *= 3 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-19 13:15:34 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 2,000 ms |
| コード長 | 625 bytes |
| 記録 | |
| コンパイル時間 | 300 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 124,428 KB |
| 最終ジャッジ日時 | 2026-05-19 13:15:42 |
| 合計ジャッジ時間 | 7,169 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
v=[[] for i in range(n)]
for i in range(n-1):
q,w=map(int,input().split());q-=1;w-=1
v[q].append(w);v[w].append(q)
f=deque([(0,0,0)]);dp=[[0]*2 for i in range(n)]
while f:
q,w,e=f.pop()
if len(v[q])>e:
f.append((q,w,e+1))
if v[q][e]!=w:
f.append((v[q][e],q,0))
else:
dp[q]=[a[q],0]
for i in v[q]:
if i==w:
continue
dp[q][0]+=max(dp[i])
dp[q][1]+=max(dp[i][0],dp[i][1]+b[i]+b[q])
print(max(dp[0]))