#P10745. [SEERC 2020] One Piece
[SEERC 2020] One Piece
Problem Description
There is a graph, which is a tree with nodes. Each edge is an undirected edge of the form with length .
You have a treasure detector. When you are at node , it returns a farthest distance , meaning that among all treasure locations that exist, the maximum distance from node to a node containing a treasure is . A graph may contain multiple treasures.
Now you are given the detector’s returned results for all . 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 , indicating the number of nodes.
The next lines each contain two integers , indicating an edge.
The next line contains numbers, where the -th number is the return value of the treasure detector when called at node .
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