I remember what someone said to me a long time ago, "The path you choose, even if you walk on your knees, you have to finish it". Friends, although the world is getting more and more impetuous, as long as we can persist in our efforts for the sake of our once pure dreams and moving motives, we can remain true to ourselves all the way, no matter what others do.
As a retired contestant, Colin hopes that all participants will always have a young heart and an eternal love for algorithms and competitive programming.
Given a tree consisting of
vertices (indexed from
to
). Vertex
is the root.
We define that vertex is an ancestor of vertex
if and only if
is on the path from
to the root.
Then we define as the set of all vertices
satisfies that
is an ancestor of
.
Now Colin and Eva give each node two integer weights
, then we define :
Please calculate for each vertex
.
The first line contains a single integer, representing the number of vertices.
For the followinglines, each line contains two integers
, representing that there is an edge connecting vertex
and vertex
. It's guaranteed that the given edges form a tree.
For the followinglines, the
-th line contains two integers
, representing the two weights of vertex
.
Outputlines.
For-th line output a single integer
.