結果

問題 No.1221 木 *= 3
ユーザー tyawanmusityawanmusi
提出日時 2020-09-04 22:59:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 616 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 63,572 KB
最終ジャッジ日時 2024-05-05 03:31:13
合計ジャッジ時間 9,743 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 25 ms
10,624 KB
testcase_04 AC 25 ms
10,752 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 AC 24 ms
10,880 KB
testcase_07 AC 594 ms
63,572 KB
testcase_08 AC 598 ms
62,656 KB
testcase_09 AC 616 ms
63,304 KB
testcase_10 AC 610 ms
62,980 KB
testcase_11 AC 605 ms
63,128 KB
testcase_12 AC 521 ms
44,756 KB
testcase_13 AC 498 ms
44,668 KB
testcase_14 AC 519 ms
44,768 KB
testcase_15 AC 514 ms
44,508 KB
testcase_16 AC 527 ms
44,572 KB
testcase_17 AC 551 ms
44,588 KB
testcase_18 AC 553 ms
44,156 KB
testcase_19 AC 563 ms
44,296 KB
testcase_20 AC 547 ms
44,056 KB
testcase_21 AC 558 ms
44,052 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