LIS On Tree
시간 제한4초메모리 제한1024 MB
매 갱신마다 i번째 값을 새 노드에 채우고, 채워진 노드들로 이루어진 임의의 경로 위에서 가장 긴 증가 부분 수열의 길이를 구한다.
문제
There were too many constructive problems in this contest, so we decided to set a standard data structure problem.
You are given a tree with labeled nodes. Each node also has a blank value initially.
The longest increasing tree subsequence between two nodes on the tree is computed as follows:
- Write down all the nonblank values from the nodes on the path from to , in order. Compute the longest increasing subsequence of the resulting sequence.
You are given updates, . For update , fill in the value at node . After each update, compute the length of the longest longest increasing tree subsequence among all pairs of nodes in the tree.
It is guaranteed that all values are distinct.
Define a sequence of integers . A subsequence where is called increasing if . An increasing subsequence is called longest if it has maximum length among all increasing subsequences.
입력
The first line of the input contains an integer , denoting the number of test cases.
The first line of each test case contains one integer .
The next lines contain two integers , denoting an undirected edge between the nodes with labels and , respectively. It is guaranteed that the input edges form a tree.
The last line of input for the testcase consists of integers , denoting the updates in order. It is guaranteed that all values are distinct.
It is guaranteed that the sum of across all test cases does not exceed .
출력
For each test case, print space-separated integers on a single line, denoting the answer after the update.
힌트
Remember that the updates **tell you the value of the x\_i^\textrm{th** node}, not that the value of node is .
An example of the process for the first tree is shown below. The yellow nodes are one potential longest increasing tree subsequence after each operation. The node's labels are 1-5 from left to right, initially with blank values.
