atcoder#ABC165F. [ABC165F] LIS on Tree
[ABC165F] LIS on Tree
Score : points
Problem Statement
We have a tree with vertices, whose -th edge connects Vertex and Vertex . Vertex has an integer written on it. For every integer from through , solve the following problem:
- We will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex to Vertex , in the order they appear. Find the length of the longest increasing subsequence of this sequence.
Here, the longest increasing subsequence of a sequence of length is the subsequence with the greatest possible value of such that and .
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex to Vertex .
10
1 2 5 3 4 6 7 3 2 4
1 2
2 3
3 4
4 5
3 6
6 7
1 8
8 9
9 10
1
2
3
3
4
4
5
2
2
3
For example, the sequence obtained from the shortest path from Vertex to Vertex is . Its longest increasing subsequence is , with the length of .