LIS on Tree
시간 제한4초메모리 제한2048 MB
각 노드에 값이 있는 트리가 주어질 때, 어떤 단순 경로를 따라 나타나는 노드들의 값이 순서대로 엄격히 증가하는 가장 긴 부분수열을 찾는다. 그 길이를 출력한다.
문제
You are given a tree of nodes. Each node has a non-negative integer value .
Let a tree subsequence be a sequence of nodes such that there exists vertices in the tree such that is a subsequence of the unique shortest path starting at and ending at .
A tree subsequence is increasing if for all we have that (Note that this corresponds to a strictly increasing sequence).
Find the length of the longest increasing tree subsequence.
입력
The first line of input contains a single integer () --- the number of nodes in the tree.
The second line of input contains integers () --- the value of each node in the tree.
The following lines each contain two integers ()--- the endpoints of edge .
It is guaranteed that the given edges form a tree.
출력
Output a single integer --- the length of the longest increasing tree subsequence.