100 atcoder#ABC214D. [ABC214D] Sum of Maximum Weights
[ABC214D] Sum of Maximum Weights
Score : points
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.
3
1 2 10
2 3 20
50
We have , , and , so we should print their sum, or .
5
1 2 1
2 3 2
4 2 5
3 5 14
76