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

建议使用的浏览器:

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

7136:Jumping Monkey

题目描述
There is a tree with $n$ nodes and $n-1$ edges that make all nodes connected. Each node $i$ has a $\textbf{distinct}$ weight $a_i$. A monkey is jumping on the tree. In one jump, the monkey can jump from node $u$ to node $v$ if and only if $a_v$ is the greatest of all nodes on the shortest path from node $u$ to node $v$. The monkey will stop jumping once no more nodes can be reached.

For each integer $k \in [1, n]$, calculate the maximum number of nodes the monkey can reach if he starts from node $k$.
输入解释
The first line of the input contains an integer $T$ $(1 \leq T \leq 10^4)$, representing the number of test cases.

The first line of each test case contains an integer $n$ $(1 \leq n \leq 10^5)$, representing the number of nodes.

Each of the following $n - 1$ lines contains two integers $u, v$ $(1 \leq u, v \leq n)$, representing an edge connecting node $u$ and node $v$. It is guaranteed that the input will form a tree.

The next line contains $n$ $\textbf{distinct}$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 10^9)$, representing the weight of each node.

It is guaranteed that the sum of $n$ over all test cases does not exceed $8 \times 10^5$.
输出解释
For each test case, output $n$ lines. The $k$-th line contains an integer representing the answer when the monkey starts from node $k$.
输入样例
2
3
1 2
2 3
1 2 3
5
1 2
1 3
2 4
2 5
1 4 2 5 3
输出样例
3
2
1
4
2
3
1
3
来自杭电HDUOJ的附加信息
Hint For the second case of the sample, if the monkey starts from node $1$, he can reach at most $4$ nodes in the order of $1 \to 3 \to 2 \to 4$.

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

源链接: HDU-7136

最后修改于 2021-10-23T19:11:41+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000/4000MS(Java/Others) 262144/262144K(Java/Others)