프로그램 명: stfd_bonsai
제한시간: 1 초

After being assaulted in the parking lot by Mr. Miyagi following the \All Valley Karate Tournament", John Kreese has come to you for assistance. Help John in his quest for justice by chopping off the leaves from Mr. Miyagi's bonsai tree!

You are given an undirected tree (i.e., a connected graph with no cycles), where each edge (i.e., branch) has a nonnegative weight (i.e., thickness). One vertex of the tree has been designated the root of the tree. The remaining vertices of the tree each have unique paths to the root; non-root vertices which are not the successors of any other vertex on a path to the root are known as leaves.

Determine the minimum weight set of edges that must be removed so that none of the leaves in the original tree are connected by some path to the root.

입력

The input will not contain duplicate edges.

출력

Print a single integer indicating the minimum total weight of edges that must be deleted in order to ensure that there exists no path from one of the original leaves to the root.

입출력 예

입력

15 15
1 2 1
2 3 2
2 5 3
5 6 7
4 6 5
6 7 4
5 15 6
15 10 11
10 13 5
13 14 4
12 13 3
9 10 8
8 9 2
9 11 3

출력

16
출처:standford/2009/

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]