結果
問題 | No.1221 木 *= 3 |
ユーザー | chineristAC |
提出日時 | 2020-09-05 12:58:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 337 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 87,104 KB |
実行使用メモリ | 111,252 KB |
最終ジャッジ日時 | 2023-08-18 19:45:41 |
合計ジャッジ時間 | 8,985 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
71,544 KB |
testcase_01 | AC | 82 ms
71,512 KB |
testcase_02 | AC | 85 ms
71,416 KB |
testcase_03 | AC | 83 ms
71,404 KB |
testcase_04 | AC | 78 ms
71,500 KB |
testcase_05 | AC | 81 ms
71,676 KB |
testcase_06 | AC | 80 ms
71,480 KB |
testcase_07 | AC | 280 ms
111,040 KB |
testcase_08 | AC | 274 ms
110,760 KB |
testcase_09 | AC | 296 ms
111,224 KB |
testcase_10 | AC | 290 ms
110,880 KB |
testcase_11 | AC | 289 ms
111,252 KB |
testcase_12 | AC | 265 ms
111,148 KB |
testcase_13 | AC | 272 ms
110,664 KB |
testcase_14 | AC | 276 ms
111,028 KB |
testcase_15 | AC | 269 ms
111,188 KB |
testcase_16 | AC | 276 ms
110,940 KB |
testcase_17 | AC | 337 ms
111,076 KB |
testcase_18 | AC | 331 ms
110,360 KB |
testcase_19 | AC | 319 ms
111,164 KB |
testcase_20 | AC | 325 ms
111,176 KB |
testcase_21 | AC | 335 ms
110,908 KB |
ソースコード
import sys from collections import deque N = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) edge = [[] for i in range(N)] for _ in range(N-1): u,v = map(int,input().split()) edge[u-1].append(v-1) edge[v-1].append(u-1) deq = deque([0]) parent = [-1] * N res = [] while deq: v = deq.popleft() res.append(v) for nv in edge[v]: if nv!=parent[v]: parent[nv] = v deq.append(nv) res = res[::-1] exist_dp = [0] * N not_exist_dp = [0] * N for v in res: #not_exist_dp not_exist_dp[v] = a[v] for nv in edge[v]: if nv!=parent[v]: not_exist_dp[v] += max(exist_dp[nv],not_exist_dp[nv]) #exist_dp for nv in edge[v]: if nv!=parent[v]: exist_dp[v] += max(b[v]+b[nv]+exist_dp[nv],not_exist_dp[nv]) print(max(exist_dp[0],not_exist_dp[0]))