Logo
(追記) (追記ここまで)

18921번 - Cost Of Subtree 다국어

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

문제

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

힌트

출처

Camp > Bytedance-Moscow Workshops Camp > Bytedance-Moscow Workshops Camp 2020 > Contest 1 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /