結果
| 問題 | No.1221 木 *= 3 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-04 23:24:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 554 bytes |
| 記録 | |
| コンパイル時間 | 218 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 54,616 KB |
| 最終ジャッジ日時 | 2024-11-26 21:03:48 |
| 合計ジャッジ時間 | 11,056 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 4 WA * 14 |
ソースコード
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(N-1):
a,b = map(int, input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
import sys
sys.setrecursionlimit(10**6)
def dfs(v, p):
if p>=0 and len(edge[v])==1:
return max(A[v],0), max(A[v],B[v]+B[p])
offs, ons = A[v],0
for u in edge[v]:
if u!=p:
off, on = dfs(u, v)
offs += off
ons += on
if p>=0:
ons += B[p]
return offs, ons
off, on = dfs(0, -1)
print(max(off,on))