結果

問題 No.3660 LIS on Tree
コンテスト
ユーザー n_bitand_n_per_3
提出日時 2026-09-04 10:27:38
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 705 ms / 2,000 ms
+ 873µs
コード長 581 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 245 ms
コンパイル使用メモリ 96,084 KB
実行使用メモリ 158,804 KB
最終ジャッジ日時 2026-09-04 10:27:48
合計ジャッジ時間 8,937 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

N = int(input())

S = list(map(int,input().split()))

connected = [[] for _ in range(N)]
for _ in range(N-1):
	a,b = map(int,input().split())
	a -= 1
	b -= 1
	connected[a].append(b)
	connected[b].append(a)

dp = [0]*N

S_ = defaultdict(list)
for i,s in enumerate(S):
	S_[s].append(i)
events = [[k,v] for k,v in S_.items()]
events.sort()

for s,arr in events:
	tasks = []
	for i in arr:
		tmp = 0
		for j in connected[i]:
			tmp = max(tmp, dp[j])
		tasks.append((i,tmp + S[i]))
	for i,res in tasks:
		dp[i] = res
ans = max(dp)
print(ans)







0