#Lutece0550. Nearby Cows
Nearby Cows
Migrated from Lutece 550 Nearby Cows
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
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 bidirectional trails ( of them in total). FJ has designed the farm so that between any two fields i and j, 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 i 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
- Line : Two space-separated integers, and .
- Lines : Each line contains two space-separated integers, and () indicating that fields and are directly connected by a trail.
- Lines : Line contains the integer . ()
Output
- Lines : Line should contain the value of .
Samples
6 2
5 1
3 6
2 4
2 1
3 2
1
2
3
4
5
6
15
21
16
10
8
11
Resources
USACO Feb 2012