結果
| 問題 | No.3660 LIS on Tree |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-30 14:12:49 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0) |
| 結果 |
AC
|
| 実行時間 | 957 ms / 2,000 ms |
| + 419µs | |
| コード長 | 398 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
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)))