結果

問題 No.1221 木 *= 3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-11-14 00:11:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 708 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 61,012 KB
最終ジャッジ日時 2023-09-30 04:27:00
合計ジャッジ時間 12,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,796 KB
testcase_01 AC 15 ms
7,864 KB
testcase_02 AC 13 ms
7,896 KB
testcase_03 AC 13 ms
7,828 KB
testcase_04 AC 13 ms
7,856 KB
testcase_05 AC 13 ms
7,752 KB
testcase_06 AC 13 ms
7,924 KB
testcase_07 AC 661 ms
59,880 KB
testcase_08 AC 708 ms
60,856 KB
testcase_09 AC 684 ms
59,812 KB
testcase_10 AC 681 ms
60,940 KB
testcase_11 AC 671 ms
61,012 KB
testcase_12 AC 545 ms
42,036 KB
testcase_13 AC 551 ms
41,788 KB
testcase_14 AC 560 ms
42,068 KB
testcase_15 AC 568 ms
41,896 KB
testcase_16 AC 572 ms
41,984 KB
testcase_17 AC 631 ms
45,428 KB
testcase_18 AC 609 ms
45,800 KB
testcase_19 AC 626 ms
45,068 KB
testcase_20 AC 609 ms
45,060 KB
testcase_21 AC 615 ms
45,080 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