Crazy Bobo

TimeLimit: 6000/3000 MS (Java/Others)  MemoryLimit: 131072/65536 K (Java/Others)
64-bit integer IO format:%I64d
未提交 | 登录后收藏
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.
SampleInput
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
SampleOutput
5
Submit
题目统计信息详细
总AC数2
通过人数2
尝试人数3
总提交量8
AC率25.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: