#abc359f. F - Tree Degree Optimization
F - Tree Degree Optimization
Score : points
问题陈述
给定一个整数序列 。对于一个有 个顶点的树 ,定义 如下:
- 设 为树 中顶点 的度数。那么,。
找出 的最小可能值。
约束条件保证答案小于 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a sequence of integers . For a tree with vertices, define as follows:
- Let be the degree of vertex in . Then, .
Find the minimum possible value of .
The constraints guarantee the answer to be less than .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
3 2 5 2
Sample Output 1
24
Consider a tree with an edge connecting vertices and , an edge connecting vertices and , and an edge connecting vertices and .
Then, $f(T) = 1^2\times 3 + 2^2\times 2 + 1^2\times 5 + 2^2\times 2 = 24$. It can be proven that this is the minimum value of .
Sample Input 2
3
4 3 2
Sample Output 2
15
Sample Input 3
7
10 5 10 2 10 13 15
Sample Output 3
128