当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5325:Crazy Bobo

题目描述
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.
输入解释
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.
输出解释
For each test output one line contains a integer,denoting the maximum size of Bobo Set.
输入样例
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
输出样例
5
来自杭电HDUOJ的附加信息
Author ZSTU
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5325

最后修改于 2020-10-25T23:21:43+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 131072/65536K(Java/Others)