시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB1951049658.537%

문제

The valuable tree with $n$ vertices grows near Byteazar's house. Edge $i$ has cost $v_i$ assigned to it.

A subtree of the tree is defined as a non-empty connected subset of its edges.

The cost of a subtree is defined as the number of edges in the subtree multiplied by the lowest value of $v_i$ in it.

Byteazar wants to make some money by selling subtrees, so he wants to know the maximum cost of a subtree of his tree.

입력

The first line contains a single integer $n$ ($2 \le n \le 10^5$) --- the number of vertices in the tree. Each of the following $n-1$ lines contains three integers $a_i$, $b_i$ and $v_i$ ($1 \le a_i, b_i \le n$; $a_i \ne b_i$; $1 \le v_i \le 10^9$) --- the vertices connected by the edge and its cost.

출력

Print one integer --- the maximum cost of a subtree of the given tree.

예제 입력 1

10
6 4 8
5 6 7
2 3 5
3 1 2
2 7 3
9 7 4
8 2 6
8 10 7
6 2 4

예제 출력 1

24

예제 입력 2

6
1 3 12
5 3 4
3 4 2
2 4 5
6 2 6

예제 출력 2

12