結果

問題 No.1221 木 *= 3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-11-12 19:26:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 422 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 60,992 KB
最終ジャッジ日時 2023-09-30 01:45:45
合計ジャッジ時間 14,865 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,892 KB
testcase_01 AC 16 ms
7,780 KB
testcase_02 AC 16 ms
7,864 KB
testcase_03 AC 18 ms
7,892 KB
testcase_04 AC 16 ms
7,772 KB
testcase_05 AC 16 ms
7,872 KB
testcase_06 AC 16 ms
7,792 KB
testcase_07 AC 856 ms
59,780 KB
testcase_08 AC 846 ms
60,992 KB
testcase_09 AC 864 ms
59,580 KB
testcase_10 AC 858 ms
60,880 KB
testcase_11 AC 862 ms
60,828 KB
testcase_12 AC 701 ms
42,048 KB
testcase_13 AC 702 ms
42,024 KB
testcase_14 AC 708 ms
41,900 KB
testcase_15 AC 705 ms
41,856 KB
testcase_16 AC 719 ms
41,828 KB
testcase_17 AC 788 ms
45,708 KB
testcase_18 AC 798 ms
45,628 KB
testcase_19 AC 795 ms
45,028 KB
testcase_20 AC 797 ms
45,168 KB
testcase_21 AC 823 ms
44,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:8: SyntaxWarning: invalid decimal literal
  d=[[0]*2for i in range(n)]

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
G=[[]for i in range(n)]
for i in range(n-1):u,v=map(int,input().split());G[u-1].append(v-1);G[v-1].append(u-1)
d=[[0]*2for i in range(n)]
def f(u,p):
 d[u][0]=a[u]
 for v in G[u]:
  if v!=p:f(v,u);d[u][0]+=max(d[v][0],d[v][1]);d[u][1]+=max(d[v][0],d[v][1]+b[u]+b[v])
 return
f(0,-1)
print(max(d[0]))
0