시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 27 | 16 | 16 | 88.889% |
You are given a tree, and each edge has a non-negative integer weight.
Let $d(u, v)$ --- The maximum of the edge weights on the unique simple path between vertices $u$ and $v$.
Find the largest $\sum_{i=2}^n{2^{d(p_{i - 1}, p_i)}}$ among all permutations of vertices $p_1, p_2, \ldots, p_n$.
The first line contains one integer $n$ ($2 \leq n \leq 100\,000$): the number of vertices in the tree.
Each of the next $n-1$ lines contains three integers $u,v,w$ ($1 \leq u, v \leq n, 0 \leq w \leq 30$), an edge in the tree with endpoints $u,v$ having weight $w$.
Print one integer: the largest $\sum_{i=2}^n{2^{d(p_{i - 1}, p_i)}}$.
5 1 2 0 2 3 0 3 4 0 4 5 1
6
10 2 1 1 3 1 1 1 4 0 5 1 2 6 4 1 2 7 2 8 4 2 8 9 3 6 10 0
42
In the first example, one of the optimal permutations is $\{4, 5, 3, 2, 1\}$.