F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Crazy Bobo

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2382    Accepted Submission(s): 833


Problem Description
Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weight $w_i$. All the weights are distrinct.
A set with m nodes ${v_1,v_2,...,v_m}$ 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 ${u_1,u_2,...,u_m}$,(that is,$w_{u_i} < w_{u_{i+1}}$ for i from 1 to m-1).For any node $x$ in the path from $u_i$ to $u_{i+1}$(excluding $u_i$ and $u_{i+1}$),should satisfy $w_x < w_{u_i}$.
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 ($1 \leq n \leq 500000$). Then following a line contains n integers $w_1,w_2,...,w_n$ ($1 \leq w_i \leq 10^9$,all the $w_i$ is distrinct).Each of the following n-1 lines contain 2 integers $a_i$ and $b_i$,denoting an edge between vertices $a_i$ and $b_i$ ($1 \leq a_i,b_i \leq n$).
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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 15:46:00, Gzip enabled