結果
問題 | No.1221 木 *= 3 |
ユーザー | marroncastle |
提出日時 | 2020-09-13 04:09:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 556 ms / 2,000 ms |
コード長 | 643 bytes |
コンパイル時間 | 759 ms |
コンパイル使用メモリ | 86,956 KB |
実行使用メモリ | 223,888 KB |
最終ジャッジ日時 | 2023-08-30 22:12:39 |
合計ジャッジ時間 | 7,619 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
71,448 KB |
testcase_01 | AC | 69 ms
71,148 KB |
testcase_02 | AC | 71 ms
71,264 KB |
testcase_03 | AC | 70 ms
71,332 KB |
testcase_04 | AC | 70 ms
71,412 KB |
testcase_05 | AC | 69 ms
71,368 KB |
testcase_06 | AC | 72 ms
71,184 KB |
testcase_07 | AC | 536 ms
214,728 KB |
testcase_08 | AC | 556 ms
223,888 KB |
testcase_09 | AC | 478 ms
216,000 KB |
testcase_10 | AC | 551 ms
217,972 KB |
testcase_11 | AC | 546 ms
218,588 KB |
testcase_12 | AC | 176 ms
102,500 KB |
testcase_13 | AC | 174 ms
102,752 KB |
testcase_14 | AC | 196 ms
102,164 KB |
testcase_15 | AC | 199 ms
102,928 KB |
testcase_16 | AC | 191 ms
103,248 KB |
testcase_17 | AC | 219 ms
101,420 KB |
testcase_18 | AC | 224 ms
101,108 KB |
testcase_19 | AC | 243 ms
101,148 KB |
testcase_20 | AC | 244 ms
101,196 KB |
testcase_21 | AC | 242 ms
101,360 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) edge = [[] for _ in range(N)] for i in range(N-1): a,b = map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) def dfs(v, p): if p>=0 and len(edge[v])==1: offs, ons = max(A[v],0), max(A[v],B[v]+B[p]) return offs, ons offs, ons = A[v],0 for u in edge[v]: if u!=p: off, on = dfs(u, v) offs += off ons += on if p==-1: return offs, ons return max(offs,ons),max(offs,ons+B[v]+B[p]) off, on = dfs(0, -1) print(max(off,on))