結果
問題 | No.1221 木 *= 3 |
ユーザー | marroncastle |
提出日時 | 2020-09-05 03:20:03 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 683 ms / 2,000 ms |
コード長 | 615 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 10,844 KB |
実行使用メモリ | 53,292 KB |
最終ジャッジ日時 | 2023-08-18 02:21:13 |
合計ジャッジ時間 | 11,997 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,852 KB |
testcase_01 | AC | 16 ms
7,776 KB |
testcase_02 | AC | 16 ms
7,828 KB |
testcase_03 | AC | 16 ms
7,764 KB |
testcase_04 | AC | 15 ms
7,776 KB |
testcase_05 | AC | 16 ms
7,768 KB |
testcase_06 | AC | 16 ms
7,776 KB |
testcase_07 | AC | 670 ms
53,292 KB |
testcase_08 | AC | 668 ms
51,188 KB |
testcase_09 | AC | 683 ms
51,936 KB |
testcase_10 | AC | 670 ms
51,464 KB |
testcase_11 | AC | 673 ms
51,608 KB |
testcase_12 | AC | 587 ms
34,196 KB |
testcase_13 | AC | 591 ms
33,496 KB |
testcase_14 | AC | 597 ms
33,456 KB |
testcase_15 | AC | 589 ms
33,532 KB |
testcase_16 | AC | 597 ms
33,612 KB |
testcase_17 | AC | 642 ms
34,108 KB |
testcase_18 | AC | 642 ms
33,008 KB |
testcase_19 | AC | 644 ms
33,072 KB |
testcase_20 | AC | 644 ms
33,104 KB |
testcase_21 | AC | 643 ms
32,980 KB |
ソースコード
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) import sys sys.setrecursionlimit(10**6) 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))