結果

問題 No.1221 木 *= 3
ユーザー mkawa2mkawa2
提出日時 2021-07-16 08:05:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 48,460 KB
最終ジャッジ日時 2023-09-19 04:21:43
合計ジャッジ時間 14,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,252 KB
testcase_01 AC 18 ms
8,152 KB
testcase_02 AC 16 ms
8,340 KB
testcase_03 AC 17 ms
8,272 KB
testcase_04 AC 17 ms
8,404 KB
testcase_05 AC 17 ms
8,008 KB
testcase_06 AC 17 ms
8,268 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 813 ms
45,336 KB
testcase_13 AC 799 ms
45,036 KB
testcase_14 AC 812 ms
45,220 KB
testcase_15 AC 805 ms
45,176 KB
testcase_16 AC 808 ms
45,228 KB
testcase_17 AC 861 ms
45,752 KB
testcase_18 AC 851 ms
48,460 KB
testcase_19 AC 857 ms
46,204 KB
testcase_20 AC 859 ms
46,376 KB
testcase_21 AC 874 ms
46,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

n = II()
aa = LI()
bb = LI()
to = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI1()
    to[u].append(v)
    to[v].append(u)

dp = [[-inf]*2 for _ in range(n)]

def dfs(u=0, par=-1):
    dp[u] = [aa[u], 0]
    for v in to[u]:
        if v == par: continue
        dfs(v, u)
        dp[u][0] += max(dp[v])
        dp[u][1] += max(dp[v][0], dp[v][1]+bb[u]+bb[v])

dfs()
print(max(dp[0]))
0