atcoder#MSOLUTIONS2019D. Maximum Sum of Minimum
Maximum Sum of Minimum
Score : points
Problem Statement
You are given a tree with vertices , and positive integers . The -th edge in the tree connects Vertex and Vertex .
We will write a positive integer on each vertex in and calculate our score as follows:
- On each edge, write the smaller of the integers written on the two endpoints.
- Let our score be the sum of the integers written on all the edges.
Find the maximum possible score when we write each of on one vertex in , and show one way to achieve it. If an integer occurs multiple times in , we must use it that number of times.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Use the following format:
where is the maximum possible score, and is the integer to write on Vertex . must be a permutation of . If there are multiple ways to achieve the maximum score, any of them will be accepted.
5
1 2
2 3
3 4
4 5
1 2 3 4 5
10
1 2 3 4 5
If we write on Vertex , respectively, the integers written on the four edges will be , for the score of . This is the maximum possible score.
5
1 2
1 3
1 4
1 5
3141 59 26 53 59
197
59 26 3141 59 53
may not be pairwise distinct.