Lingering Regret
Time limit3sMemory limit1024 MB
For each valley, the task counts how many valleys Uk-je can reach by jumping down the source-rooted tree under the bounce rule, starting from that valley.
Problem
Uk-je regrets the problem he wrote, Valley Overflow, so he is imagining what his life will be like in the future as a poached chicken seller.
In a deep mountain valley of Nonsan Training Center, Uk-je lives after a gift wrapping factory went under in the Fourth Industrial Revolution. He sold poached chicken by the valley until he was drafted as a trainee.
Nonsan Valley has terraced valleys connected in a tree shape by streams. Any two valleys are joined by exactly one path. Valley is at altitude meters. Valley 1 is the source, and every stream flows away from the source.
During shooting practice, Uk-je lost shell casings, one of which fell into each valley. He jumps to search for them and collect them.
When he jumps from a valley at altitude to a valley at altitude (where ), he bounces up meters from . He then rises to altitude and can move to a valley with . Then he bounces up again by meters. Uk-je can only jump in the same direction as the streams. Jumps never change valley heights or stream directions.

means Uk-je jumps from to , where and stand for the altitudes of the two valleys. For , Uk-je bounces meters and rises to altitude 5. He can then reach at most. and are impossible. For , he jumps to altitude 5 via , falls into the valley at altitude 2, and bounces meters, ending at altitude 3.5. In the example above, starting from 8 lets him reach every valley.
Uk-je does not even know which valley he is in. Assuming Uk-je starts in each valley, find how many shell casings he can recover. Uk-je can clone himself without limit, so each clone may take a different path to recover shells.
Input
The first line contains the number of valleys .
The second line contains the altitudes , separated by spaces.
Each of the next lines contains the two valley numbers connected by one stream, separated by a space.
Output
Print numbers on one line, separated by spaces. The -th number is the count of shell casings Uk-je can recover if he starts in valley .
Constraints
()
The streams connect the valleys in a tree shape.