結果

問題 No.3660 LIS on Tree
コンテスト
ユーザー tyawanmusi
提出日時 2026-08-30 14:12:49
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 957 ms / 2,000 ms
+ 419µs
コード長 398 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 828 ms
コンパイル使用メモリ 21,408 KB
実行使用メモリ 69,196 KB
最終ジャッジ日時 2026-08-30 14:13:03
合計ジャッジ時間 10,229 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
edge = [list(map(int, input().split()))for _ in range(n - 1)]
edge.sort(key = lambda x: min(a[x[0] - 1], a[x[1] - 1]))
for x, y in edge:
    if a[x - 1] == a[y - 1]:
        continue
    if a[x - 1] < a[y - 1]:
        x, y = y, x
    ans[x - 1] = max(ans[x - 1], a[y - 1] + ans[y - 1])
print(max(ans[i] + a[i] for i in range(n)))
0