## Yet Another Contest 3 P2 - Work Experience

View as PDF

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 512M

Author:
Problem type

Josh, Nils, and Mike are being allocated to various work experience sites!

The town consists of different buildings indexed from to , connected by bidirectional roads such that it is possible to get from any building to any other building using only the roads. The -th road connects buildings and . Josh, Nils, and Mike will each be allocated to one of the buildings to undergo work experience there. Note that more than one of them can be allocated to the same building.

After a long day's work, they plan to meet up with each other. First, they will select one of the buildings. Then, each of them will walk from their current building to the selected building along the roads, taking the route with the fewest roads possible. Exhausted from all of the work, they will select the building such that the total number of roads traversed by all of them is minimised. If multiple buildings can be selected whilst minimising the total number of roads traversed, then out of those buildings, they will select the building with the lowest index.

However, none of them have been allocated to a building yet. All buildings are understaffed, so any allocation of Josh, Nils, and Mike to the buildings is possible. For each building , they would like to know the number of different ways to allocate them to the buildings such that they will select and meet up at building . Two ways are considered different if any of Josh, Nils, or Mike are allocated to different buildings amongst the two ways.

#### Constraints

It is guaranteed that any building is reachable from any other building by traversing the roads.

The graph is linear. More specifically, for , and .

Note that Subtask 2 must be passed for this subtask to be evaluated.

Note that all previous subtasks must be passed for this subtask to be evaluated.

#### Input Specification

The first line of input contains a single integer, .

The -th of the following lines of input contain two space-separated integers and , representing that the -th road connects buildings and .

#### Output Specification

Print a single line containing space-separated integers. The -th of these integers should be the number of different ways to allocate Josh, Nils and Mike to the buildings such that they will select and meet up at building .

#### Sample Input

5
1 2
2 3
2 4
1 5

#### Sample Output

31 55 13 13 13

#### Explanation

Let's consider the scenario where Josh is allocated to building , Nils is allocated to building , and Mike is allocated to building .

If they were to meet up at building , they would traverse a total of roads:

• Josh would not need to move at all, so he would traverse roads.
• Nils would take the second road to building , and then take the first road to building , traversing roads.
• Mike would take the -th road, arriving at building after traversing road.

In total, they would traverse roads. It can be shown that choosing any other building to meet up at would require a greater total number of traversed roads, so in this scenario, they would select and meet up at building .

Considering all scenarios, it can be shown that:

• In scenarios, building is selected.
• In scenarios, building is selected.
• In scenarios, building is selected.
• In scenarios, building is selected.
• In scenarios, building is selected.