結果
| 問題 | No.3660 LIS on Tree |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-08-30 14:24:46 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
AC
|
| 実行時間 | 679 ms / 2,000 ms |
| + 541µs | |
| コード長 | 551 bytes |
| 記録 | |
| コンパイル時間 | 474 ms |
| コンパイル使用メモリ | 96,360 KB |
| 実行使用メモリ | 144,676 KB |
| 最終ジャッジ日時 | 2026-08-30 14:25:02 |
| 合計ジャッジ時間 | 8,281 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
import sys
from functools import cache
sys.setrecursionlimit(2 * 10**5 + 10)
N = int(input())
S = [int(s) for s in input().split()]
tree = [[] for _ in range(N)]
for _ in range(N - 1):
u, v = [int(s) - 1 for s in input().split()]
tree[u].append(v)
tree[v].append(u)
order = sorted([*range(N)], key=lambda i: S[i])
@cache
def dp(v):
res = 0
for to in tree[v]:
if S[to] <= S[v]:
continue
res = max(res, dp(to))
return res + S[v]
ans = 0
for i in order:
ans = max(ans, dp(i))
print(ans)