#P1533. Send the Fool Further! (easy)

Send the Fool Further! (easy)

Send the Fool Further! (easy)

题面翻译

给你一棵有 nn 个节点并以节点 00 为根的树,每条边有一个权值,权值为正整数。

让你从根开始找一条路径,路径的边的权值之和最大。

题目描述

Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.

Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?

Heidi's n n friends are labeled 0 0 through n1 n-1 , and their network of connections forms a tree. In other words, every two of her friends a a , b b know each other, possibly indirectly (there is a sequence of friends starting from a a and ending on b b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n1 n-1 pairs of friends who know each other directly.

Jenny is given the number 0 0 .

输入格式

The first line of the input contains the number of friends n n ( 3<=n<=100 3<=n<=100 ). The next n1 n-1 lines each contain three space-separated integers u u , v v and c c ( 0<=u,v<=n1 0<=u,v<=n-1 , 1<=c<=104 1<=c<=10^{4} ), meaning that u u and v v are friends (know each other directly) and the cost for travelling between u u and v v is c c .

It is guaranteed that the social network of the input forms a tree.

输出格式

Output a single integer – the maximum sum of costs.

样例 #1

样例输入 #1

4
0 1 4
0 2 2
2 3 3

样例输出 #1

5

样例 #2

样例输入 #2

6
1 2 3
0 2 100
1 4 2
0 3 7
3 5 10

样例输出 #2

105

样例 #3

样例输入 #3

11
1 0 1664
2 0 881
3 2 4670
4 2 1555
5 1 1870
6 2 1265
7 2 288
8 7 2266
9 2 1536
10 6 3378

样例输出 #3

5551

提示

In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 2 (incurring a cost of 100 100 ), then friend 2 2 sends her to friend 1 1 (costing Heidi 3 3 ), and finally friend 1 1 relays her to friend 4 4 (incurring an additional cost of 2 2 ).