#P10935. [2015杭电多校]Crazy Bobo
[2015杭电多校]Crazy Bobo
Crazy Bobo
Problem Description
Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weight . All the weights are distrinct. A set with m nodes is a Bobo Set if:
- The subgraph of his tree induced by this set is connected.
- After we sort these nodes in set by their weights in ascending order,we get ,(that is, for i from 1 to m-1).For any node in the path from to (excluding and ),should satisfy . Your task is to find the maximum size of Bobo Set in a given tree.
Input
The input consists of several tests. For each tests: The first line contains a integer n (). Then following a line contains n integers (,all the is distrinct).Each of the following n-1 lines contain 2 integers and ,denoting an edge between vertices and (). The sum of n is not bigger than 800000.
Output
For each test output one line contains a integer,denoting the maximum size of Bobo Set.
Sample Input
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
Sample Output
5
Author
ZSTU
Source
2015 Multi-University Training Contest 3