結果
| 問題 | No.3660 LIS on Tree |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-08-30 15:24:26 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
AC
|
| 実行時間 | 514 ms / 2,000 ms |
| + 102µs | |
| コード長 | 518 bytes |
| 記録 | |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 95,724 KB |
| 実行使用メモリ | 152,972 KB |
| 最終ジャッジ日時 | 2026-08-30 15:24:35 |
| 合計ジャッジ時間 | 7,619 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
from collections import defaultdict
from functools import cache
import sys
sys.setrecursionlimit(10**6)
N = int(input())
S = list(map(int, input().split()))
adj = defaultdict(list)
for _ in range(N-1):
a, b = map(lambda x: int(x)-1, input().split())
adj[a].append(b)
adj[b].append(a)
@cache
def dfs(v):
s = S[v]
res = s
for to in adj[v]:
if s <= S[to]: continue
res = max(res, s + dfs(to))
return res
ans = 0
for i in range(N):
ans = max(ans, dfs(i))
print(ans)
norioc