8560: Eezie and Pie

内存限制:512 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

Eezie, a pie maniac, would like to have some pies with her friends on a hot summer day. However, the weather is so hot that she can't go outdoors and has to call for the delivery service.

The city Eezie lives in can be represented by N nodes connected by N−1 edges, and the city center is node 1. In other words, the city is a rooted tree, root of which is node 1. There are N pie houses in the city, the i-th on node i. For some reason, a pie house on node i can only deliver its pie to nodes on the simple path from node i to node 1.

Eezie is a bit worried that a pie might lose its flavor during the deliver. After some careful calculation, she decided that a pie from the i-th pie house can maintain its flavor if the distance it is delivered does not exceed its flavor-loss-distance di. The distance between two nodes on the tree is the number of edges on the simple path between them.

Now, Eezie wants to order some pies for all her friends who live on different nodes of the tree. Therefore, she wants you to calculate for each node how many pie houses can deliver their pie to the node without flavor loss.

输入格式

The first line contains an integer N(1≤N≤2×106), representing the number of nodes of the city Eezie lives in.


Each of the next N−1 lines contains two integers u,v(1≤u,v≤N)u,  representing an edge. It is guaranteed that the edges form a tree.

The last line contains N integers d1,d2,⋯,dN(0≤di≤N), representing the maximum travel distances for pies from pie houses.

输出格式

Output N integers in a line, the i-th integer representing the answer for node i.

输入样例 复制

10
1 2
2 3
2 4
3 5
4 6
4 7
1 8
8 9
8 10
0 0 1 2 2 5 3 1 0 2

输出样例 复制

6 6 2 3 1 1 1 2 1 1

分类标签