結果

問題 No.1221 木 *= 3
ユーザー tyawanmusityawanmusi
提出日時 2020-09-04 22:59:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 591 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 61,608 KB
最終ジャッジ日時 2023-08-17 20:37:41
合計ジャッジ時間 9,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,804 KB
testcase_01 AC 16 ms
7,972 KB
testcase_02 AC 16 ms
7,724 KB
testcase_03 AC 16 ms
7,936 KB
testcase_04 AC 16 ms
7,984 KB
testcase_05 AC 16 ms
7,940 KB
testcase_06 AC 15 ms
7,940 KB
testcase_07 AC 554 ms
61,608 KB
testcase_08 AC 591 ms
60,284 KB
testcase_09 AC 583 ms
61,044 KB
testcase_10 AC 557 ms
60,412 KB
testcase_11 AC 583 ms
60,644 KB
testcase_12 AC 510 ms
42,092 KB
testcase_13 AC 486 ms
41,720 KB
testcase_14 AC 496 ms
41,796 KB
testcase_15 AC 520 ms
41,876 KB
testcase_16 AC 509 ms
41,860 KB
testcase_17 AC 567 ms
41,996 KB
testcase_18 AC 533 ms
41,264 KB
testcase_19 AC 548 ms
41,468 KB
testcase_20 AC 540 ms
41,520 KB
testcase_21 AC 554 ms
41,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(1000000)

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  aa,bb=map(int,input().split())
  aa-=1
  bb-=1
  edge[aa].append(bb)
  edge[bb].append(aa)
dp=[[a[i],0]for i in range(n)]
def dfs(r,node):
  if len(edge[node])==1 and r!=-1:
    return dp[node]
  x=a[node]
  y=0
  for mode in edge[node]:
    if mode==r:continue
    xx,yy=dfs(node,mode)
    x+=max(xx,yy)
    y+=max(xx,b[node]+b[mode]+yy)
  return [x,y]
x,y=dfs(-1,0)
print(max(x,y))
0