結果

問題 No.3660 LIS on Tree
コンテスト
ユーザー norioc
提出日時 2026-08-30 15:19:48
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 875 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 167,900 KB
最終ジャッジ日時 2026-08-30 15:20:04
合計ジャッジ時間 5,501 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

try:
    import pypyjit
    pypyjit.set_param('max_unroll_recursion=-1')
except ModuleNotFoundError:
    pass

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

adj = defaultdict(list)
adj2 = 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)

    if S[a] > S[b]:
        adj2[a].append(b)
    if S[a] < S[b]:
        adj2[b].append(a)


def dfs(v):
    s = S[v]
    res = s
    for to in adj2[v]:
        res = max(res, s + dfs(to))

    return res


ans = 0
for i in range(N):
    b = True
    small = False
    for to in adj[i]:
        if S[to] > S[i]:
            b = False
            break

        if S[to] < S[i]:
            small = True

    if b and small:
        ans = max(ans, dfs(i))

print(ans)
0