PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000224. Tổng trọng số lớn nhất trên đường đi (Sum of Maximum Weights)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng trọng số lớn nhất trên đường đi (Sum of Maximum Weights)
Sum of Maximum Weights
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a weighted tree with vertices numbered to , and all edge weights are positive integers. For two different vertices , let be the maximum edge weight along their unique simple path.
Compute the sum of over every unordered pair .
Input
- The first line contains integer .
- Each of the following lines contains , describing one tree edge.
Output
Print one integer: the requested sum.
Subtasks
- Subtask 1 (20 points): ; ; ; các cạnh tạo thành cây.
- Subtask 2 (30 points): ; ; ; các cạnh tạo thành cây.
- Subtask 3 (50 points): ; ; ; các cạnh tạo thành cây.
Examples
Input
3
1 2 10
2 3 20
Output
50
Explanation
The three pairs are with value , with value , and , whose path contains weights and thus has value . Their sum is .