#abc214d. D - Sum of Maximum Weights
D - Sum of Maximum Weights
Score : points
问题描述
我们有一个包含 个顶点的树,顶点编号为 。
第 条边()连接顶点 和顶点 ,并具有权重 。
对于不同的顶点 和 ,令 表示从顶点 到顶点 的最短路径中包含的最大权重边。
求 $\displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j)$。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a tree with vertices numbered .
The -th edge connects Vertex and Vertex and has a weight .
For different vertices and , let be the greatest weight of an edge contained in the shortest path from Vertex to Vertex .
Find $\displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j)$.
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 2 10
2 3 20
Sample Output 1
50
We have , , and , so we should print their sum, or .
Sample Input 2
5
1 2 1
2 3 2
4 2 5
3 5 14
Sample Output 2
76
update @ 2024/3/10 09:31:34