#P3047. [USACO12FEB] Nearby Cows G
[USACO12FEB] Nearby Cows G
Description
Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in that field, but also for cows visiting from nearby fields.
Specifically, FJ's farm consists of fields , where some pairs of fields are connected with bi-directional trails ( of them in total). FJ has designed the farm so that between any two fields and , there is a unique path made up of trails connecting between and . Field is home to cows, although cows sometimes move to a different field by crossing up to trails .
FJ wants to plant enough grass in each field to feed the maximum number of cows that could possibly end up in that field -- that is, the number of cows that can potentially reach field by following at most trails. Given the structure of FJ's farm and the value of for each field , please help FJ compute for every field .
Input Format
-
Line : Two space-separated integers, and .
-
Lines to : Each line contains two space-separated integers, and indicating that fields and are directly connected by a trail.
-
Lines to : Line contains the integer .
Output Format
- Lines to : Line should contain the value of .
6 2
5 1
3 6
2 4
2 1
3 2
1
2
3
4
5
6
15
21
16
10
8
11
Hint
There are fields, with trails connecting , , , , and . Field has cows.
Field has cows within a distance of trails, etc.
京公网安备 11011102002149号