Xiao F has planted a tree with
Over the next few days, Xiao F makes
Xiao F also has
Since each node has a different height and position, the lengths of thread between different nodes may differ. But since these trees are identical and the distances between neighboring trees are the same, for any
So we can describe these threads with a sequence
To test the results, the spiders have a tree-climbing competition. The
Help the spiders to calculate each of their shortest path lengths.
Subtask # | Score | Constraints |
---|---|---|
1 | 3 | |
2 | 5 | |
3 | 11 | |
4 | 12 | The tree is a line graph. |
5 | 9 | The tree is a star graph. |
6 | 22 | |
7 | 18 | |
8 | 20 | No additional constraints |
The first line of input contains 3 integers
The second line of input contains
The next
The next
Output
Sample Input 1 | Sample Output 1 |
4 3 2 |
11
|
Subtask | Score |
---|---|
1 | 3 |
2 | 5 |
3 | 11 |
4 | 12 |
5 | 9 |
6 | 22 |
7 | 18 |
8 | 20 |
9 | 0 |