結果

問題 No.1221 木 *= 3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-11-14 00:12:01
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 894 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 61,060 KB
最終ジャッジ日時 2023-09-30 04:27:29
合計ジャッジ時間 14,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,788 KB
testcase_01 AC 18 ms
7,788 KB
testcase_02 AC 18 ms
7,952 KB
testcase_03 AC 19 ms
7,816 KB
testcase_04 AC 17 ms
7,824 KB
testcase_05 AC 17 ms
7,796 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 869 ms
60,468 KB
testcase_08 AC 871 ms
60,924 KB
testcase_09 AC 869 ms
59,812 KB
testcase_10 AC 891 ms
60,796 KB
testcase_11 AC 894 ms
61,060 KB
testcase_12 AC 725 ms
42,064 KB
testcase_13 AC 719 ms
41,956 KB
testcase_14 AC 728 ms
41,964 KB
testcase_15 AC 720 ms
41,872 KB
testcase_16 AC 750 ms
42,012 KB
testcase_17 AC 822 ms
45,764 KB
testcase_18 AC 817 ms
45,800 KB
testcase_19 AC 823 ms
45,096 KB
testcase_20 AC 824 ms
45,016 KB
testcase_21 AC 830 ms
44,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:9: SyntaxWarning: invalid decimal literal
  d=[[0]*2for i in range(n)]

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
def M():return map(int,input().split())
n=int(input())
a=list(M())
b=list(M())
G=[[]for i in range(n)]
for i in range(n-1):u,v=M();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