LIS on tree - MarisaOJ: Marisa Online Judge

LIS on tree

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree of $n$ vertices, vertex $i$ has integer $A_i$. Find a subset of vertices $u_1,u_2,..,u_k$ so that for every pair $(i,j)$ that $1 \le i, j \le k$, if $u_i$ is an ancestor of $u_j$ then $A_{u_j} < A_{u_i}$. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. - The next $n$ lines, each line contains two integers $u, v$, there is an edge between $u$ and $v$. ### Output - Print a single integer is the answer. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i \le 10^9$. - $1 \le u, v \le n$. ### Example Input: ``` 4 1 4 2 3 1 2 2 3 2 4 ``` Output: ``` 3 ```