#P10745. [SEERC 2020] One Piece

[SEERC 2020] One Piece

Problem Description

There is a graph, which is a tree with nn nodes. Each edge is an undirected edge of the form (u,v)(u,v) with length 11.

You have a treasure detector. When you are at node ii, it returns a farthest distance xx, meaning that among all treasure locations that exist, the maximum distance from node ii to a node containing a treasure is xx. A graph may contain multiple treasures.

Now you are given the detector’s returned results for all 1in1 \leq i \leq n. Please output the array obtained by sorting all nodes in decreasing order of the probability that there is a treasure at that node.

Input Format

The first line contains an integer n (1n2.5×105)n\ (1 \leq n \leq 2.5 \times 10^5), indicating the number of nodes.

The next n1n-1 lines each contain two integers u,vu,v, indicating an edge.

The next line contains nn numbers, where the ii-th number is the return value of the treasure detector when called at node ii.

Output Format

Output the array obtained by sorting all nodes in decreasing order of the probability that there is a treasure at that node.

If probabilities are equal, sort by node index in increasing order.

5
1 2
1 3
2 4
2 5
2 2 3 3 3
3 4 5 1 2
4
2 1
3 2
3 4
1 0 1 2
2 1 3 4

Hint

Translated by ChatGPT 5