結果

問題 No.1221 木 *= 3
ユーザー marroncastlemarroncastle
提出日時 2020-09-04 23:24:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 554 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 52,040 KB
最終ジャッジ日時 2023-08-17 20:46:48
合計ジャッジ時間 11,285 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,808 KB
testcase_01 AC 16 ms
7,896 KB
testcase_02 AC 15 ms
7,940 KB
testcase_03 WA -
testcase_04 AC 16 ms
7,840 KB
testcase_05 AC 15 ms
7,840 KB
testcase_06 AC 16 ms
7,764 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 599 ms
33,468 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0