LIS On Tree
Time limit4sMemory limit1024 MB
Given a tree where node x_i receives value i in order, report after each update the longest increasing subsequence over any path's nonblank values.
- Level
Hard9 of 10
- Topics
- Tree, Dynamic programming, Segment tree, Binary search
- Solved
- No attempts yet
Problem
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 starts with a blank value.
The longest increasing tree subsequence between two nodes is computed as follows:
- Write down all the nonblank values on the path from to , in order. Compute the longest increasing subsequence (LIS) of the resulting sequence.
A subsequence with is increasing if . A longest increasing subsequence is one with the maximum length among all increasing subsequences.
You are given updates . Update writes the value at node . After each update, compute the maximum longest increasing tree subsequence length over all pairs of nodes .
All are distinct.
Input
The first line contains the number of test cases ().
Each test case starts with one integer (). The next lines each contain two integers and (), an undirected edge between nodes and . The edges form a tree.
The last line of the test case contains the updates . The sum of over all test cases does not exceed .
Output
For each test case, print space-separated integers on a single line. The -th integer is the answer after the -th update.
Hint
An update tells you the value of node , not that the value of node is .