Recovering the Populations
Time limit4sMemory limit256 MB
Given a tree and the distance-weighted sums at each node, recover the node weights that produce them.
Problem
Byteasar is preparing a problem for a programming contest. He has already written a draft of the statement.
Byteotia has cities joined by two-way roads, laid out so that the road network lets you travel between any two cities. Driving the road between two directly connected cities takes one hour. The cities are numbered from to , and inhabitants live in city .
An election is held in Byteotia next year. To keep full control over the vote, the king of Byteotia decided that the vote takes place in a single city. Every inhabitant of Byteotia travels to the city with the ballot box along a shortest route and votes there. All that is left is to choose the city that holds the vote, and this choice depends on many factors. In particular, for every city we want to compute the total time all inhabitants of Byteotia need to reach city . Call this value . [...]
Byteasar had already prepared unusually hard tests for the problem, but he accidentally lost half of the data. All that is left of each test is the part describing the roads and the output file with the values . From that alone Byteasar wants to recover the number of inhabitants of every city of Byteotia.
Input
The first line contains an integer (), the number of cities in Byteotia. Each of the next lines contains two integers , () describing one road, which means that city and city are joined by a road. The road network connects all cities.
The next line contains a sequence of integers ().
Output
Print a sequence of integers on one line, separated by single spaces. The number is the number of inhabitants of city of Byteotia. Solving Byteasar's problem for the printed sequence has to give back the sequence from the input.
The input always admits an answer. Once the road network and the sequence are fixed, only one sequence satisfies the condition, so print that sequence.